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


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


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

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

#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("sum of even is:%d", se);
   printf("\nsum of Odd is:%d", so);

   return 0;
}

Output:

Enter 5 numbers:2 3 4 5 6                                                                                                              
sum of even is:12                                                                                                                      
sum of Odd is:8

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.