Tuesday 13 January 2015

Cpp Program to find all the even and odd numbers in an array


This is a Cpp Program which finds all the even and odd numbers in an array.

Here we check all the array elements for even condition that number % 2 is 0 or not , now we print all the numbers satisfies this condition as  even numbers and the other numbers as odd numbers.

PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    int n,i;
    cout << "\nEnter the no of Elements: \t";
    cin >> n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cout << "\nEnter Element " <<  i+1 << ": \t";
        cin >> arr[i];
    }
    cout  << "\nThe EVEN Numbers are : \t";
    for(i=0;i<n;i++){
        if(arr[i]%2 == 0)

        cout << "\t" << arr[i];
    }
    cout  << "\nThe ODD Numbers are : \t";
    for(i=0;i<n;i++){
        if(arr[i]%2 != 0)

        cout << "\t" << arr[i];
    }
    return 0;
}

OUTPUT : 
Cpp - Even or Odd elements in an array

No comments:

Post a Comment