C++ Program to find even and odd elements in the array


In this program, You will learn how to find even and odd elements in array in C++.


for (i = 0; i < 10; i++) {
      if (arr[i] % 2 == 0) {
          //statement 
      }
}

Example: How to find even and odd elements in an array in C++.

#include<iostream>
using namespace std;

int main() {

    int arr[10], i;

    cout << "Enter any 5 numbers:";
    for (i = 0; i < 5; i++) {
        cin >> arr[i];
    }

    cout << "All even list is:";
    for (i = 0; i < 5; i++) {
        if (arr[i] % 2 == 0)
            cout << arr[i] << " ";
    }

    cout << "\nAll odd list is:";
    for (i = 0; i < 5; i++) {
        if (arr[i] % 2 != 0)
            cout << arr[i] << " ";
    }

    return 0;
}

Output:

Enter any 5 numbers:2 3 4 5 6
All even list is:2 4 6 
All odd list is:3 5