C Program to find even and odd elements in array


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


if (arr[i] % 2 == 0) { }


Example: How to find even and odd elements in array in c

Run it Now
#include<stdio.h>

int main() {

   int arr[5], i;

   printf("Enter 5 Numbers :");
   for (i = 0; i < 5; i++) {
       scanf("%d", &arr[i]);
   }

   printf("\nList of Even is :");
   for (i = 0; i < 5; i++) {
       if (arr[i] % 2 == 0) {
           printf("%d ", arr[i]);
       }
   }

   printf("\nList of Odd is :");
   for (i = 0; i < 5; i++) {
       if (arr[i] % 2 != 0) {
           printf("%d ", arr[i]);
       }
   }

   return 0;
}

Output:

Enter 5 Numbers :2 3 4 5 6
List of Even is :2 4 6
List of Odd is :3 5