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 the array in c.


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

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

#include<stdio.h>

int main() {

   int arr[5], i;

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

   printf("List of even numbers:");
   for (i = 0; i < 5; i++) {
       if (arr[i] % 2 == 0) {
           printf("%d ", arr[i]);
       }
   }

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

   return 0;
}

Output:

Enter 5 numbers:10 11 12 13 14 15                                                                                                      
List of even numbers:10 12 14                                                                                                          
List of odd numbers:11 13