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
}
#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;
}
Enter 5 numbers:2 3 4 5 6
sum of even is:12
sum of Odd is:8