C Program to find sum of even and odd elements in array


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


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


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

Run it Now
#include<stdio.h>

int main() {

   int arr[5], i, se = 0, so = 0;

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

   for (i = 0; i < 5; i++) {
       if (arr[i] % 2 == 0) {
           se = se + arr[i];
       } else {
           so = so + arr[i];
       }
   }
   printf("\nThe sum of Even is :%d", se);
   printf("\nThe sum of Odd is :%d", so);

   return 0;
}

Output:

Enter 5 Numbers :2 3 4 5 6
The sum of Even is :12
The sum of Odd is :8