Thursday 26 June 2014

C++ program to print even, odd numbers in an array


Here is a C++ program to print even, odd numbers in an array


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a[20],num;
    cout<<"How many elements to be stored (max 20) : ";
    cin>>num;
    cout<<"Enter elements of array a1 : ";
    for(int i=0;i<num;i++)
        cin>>a[i];
    cout<<"Odd elements : ";
    for(int i=0;i<num;i++)
       if(a[i]%2==1)
           cout<<a[i]<<" ";
    cout<<endl<<"Even elements  : ";
    for(int i=0;i<num;i++)
       if(a[i]%2==0)
           cout<<a[i]<<" ";
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment