In this tutorial, i am going to show you how to calculate or find sum of even and odd numbers in an array using in c programs.

## All C Programs and Algorithm to Sum of Even and Odd Numbers in an Array

- C Program to Sum of Even and Odd Numbers in an Array using For Loop
- C Program to Sum of Even and Odd Numbers in an Array using While Loop
- C Program to Sum of Even and Odd Numbers in an Array using Function

### C Program to Sum of Even and Odd Numbers in an Array using For Loop

/* C Program to find Sum of Even and Odd Numbers in an Array */ #include<stdio.h> int main() { int Size, i, a[10]; int Even_Sum = 0, Odd_Sum = 0; printf("\n Please Enter the Size of an Array : "); scanf("%d", &Size); printf("\nPlease Enter the Array Elements\n"); for(i = 0; i < Size; i++) { scanf("%d", &a[i]); } for(i = 0; i < Size; i ++) { if(a[i] % 2 == 0) { Even_Sum = Even_Sum + a[i]; } else { Odd_Sum = Odd_Sum + a[i]; } } printf("\n The Sum of Even Numbers in this Array = %d ", Even_Sum); printf("\n The Sum of Odd Numbers in this Array = %d ", Odd_Sum); return 0; }

The result of the above c program; as follows:

Please Enter the Size of an Array : 5 Please Enter the Array Elements 1 2 3 4 5 The Sum of Even Numbers in this Array = 6 The Sum of Odd Numbers in this Array = 9

### C Program to Sum of Even and Odd Numbers in an Array using While Loop

/* C Program to find Sum of Even and Odd Numbers in an Array */ #include<stdio.h> int main() { int Size, i, j = 0, a[10]; int Even_Sum = 0, Odd_Sum = 0; printf("\n Please Enter the Size of an Array : "); scanf("%d", &Size); printf("\nPlease Enter the Array Elements\n"); for(i = 0; i < Size; i++) { scanf("%d", &a[i]); } while(j < Size) { if(a[j] % 2 == 0) { Even_Sum = Even_Sum + a[j]; } else { Odd_Sum = Odd_Sum + a[j]; } j++; } printf("\n The Sum of Even Numbers in this Array = %d ", Even_Sum); printf("\n The Sum of Odd Numbers in this Array = %d ", Odd_Sum); return 0; }

The result of the above c program; as follows:

Please Enter the Size of an Array : 5 Please Enter the Array Elements 1 5 8 9 10 The Sum of Even Numbers in this Array = 18 The Sum of Odd Numbers in this Array = 15

### C Program to Sum of Even and Odd Numbers in an Array using Function

/* C Program to Count Even and Odd Numbers in an Array */ #include<stdio.h> int CountEvenNumbers(int a[], int Size); int CountOddNumbers(int a[], int Size); int main() { int Size, i, a[10]; int Even_Count = 0, Odd_Count = 0; printf("\n Please Enter the Size of an Array : "); scanf("%d", &Size); printf("\nPlease Enter the Array Elements : "); for(i = 0; i < Size; i++) { scanf("%d", &a[i]); } Even_Count = CountEvenNumbers(a, Size); Odd_Count = CountOddNumbers(a, Size); printf("\n Total Number of Even Numbers in this Array = %d ", Even_Count); printf("\n Total Number of Odd Numbers in this Array = %d ", Odd_Count); return 0; } int CountEvenNumbers(int a[], int Size) { int i, Even_Count = 0; printf("\n List of Even Numbers in this Array: "); for(i = 0; i < Size; i ++) { if(a[i] % 2 == 0) { printf("%d ", a[i]); Even_Count++; } } return Even_Count; } int CountOddNumbers(int a[], int Size) { int i, Odd_Count = 0; printf("\n List of Odd Numbers in this Array: "); for(i = 0; i < Size; i ++) { if(a[i] % 2 != 0) { printf("%d ", a[i]); Odd_Count++; } } return Odd_Count; }

The result of the above c program; as follows:

Please Enter the Size of an Array : 5 Please Enter the Array Elements : 10 5 25 30 40 List of Even Numbers in this Array: 10 30 40 List of Odd Numbers in this Array: 5 25 Total Number of Even Numbers in this Array = 3 Total Number of Odd Numbers in this Array = 2