Showing posts with label Odd and Even Number Lister. Show all posts
Showing posts with label Odd and Even Number Lister. Show all posts

Thursday, July 24, 2014

Odd and Even Number Determiner in C++

Array is one of the basic data structure in programming that is very important for beginning and experienced programmers able to understand and eventually to master. By definition an array is a list of values belongs with the same variable name and data type. For example int values[100] it means I have 100 elements or index under the variable name values and its data type for all the elements is integer.

One of the common applications of arrays in computer programming for example is that we ask the user to enter five numbers and then we want to display all the five numbers being given by our user earlier in our program. There are several solution to tackle this problem but the most efficient way is to use for loop statement and an array declaration just like this one int x[5] where x has five elements or index values. 

In this article I would like to share with you one of my program that I wrote for my class in C++ programming I called this program Odd and Even Number Determiner written entirely in C++ programming language. What the program will do is very simple it will ask the user to enter ten integer numbers and then it will display the list of numbers that are Odd and Even Numbers by generating a report.

I hope you will find my work useful in learning how to user one dimensional array and for loop statements in C++.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

Thank you very much.


Sample Output of Our Program

Program Listing

#include <iostream>

using namespace std;

main() {
 int val[10];

cout << "\n\n";
cout << "<======== ODD AND EVEN NUMBER DETERMINER ======>";
cout << "\n\n";

 for (int x=0; x<10; x++) {
    cout << "Enter item no. " << x+1 << ": ";
    cin >> x[val];
 }
cout << "\n\n";
cout << "<======= GENERATED REPORT ======>";
cout << "\n\n";
 cout << "LIST OF ODD NUMBERS";
 cout << "\n\n";
 for (int x=0; x<10; x++) {
     if (x[val] % 2 == 0) {
       }
       else {
        cout << " " << x[val] <<" ";
       }
     }
  cout << "\n\n";
 cout << "LIST OF EVEN NUMBERS";
 cout << "\n\n";
 for (int x=0; x<10; x++) {
     if (x[val] % 2 == 0) {
       cout << " " << x[val] <<" ";
       }
       else {
       }
     }
cout << "\n\n";
cout <<"\t Thank You For Using This Program.";
cout << "\n\n";
}