C Programming Code Examples C > Arrays and Matrices Code Examples program to count even and odd elements in an array program to count even and odd elements in an array Write a C program to read elements in an array from user and count total number of even and odd elements in the given array. How to find total number of even and odd elements in a given array using C programming. Logic to count total even or odd elements in array Input elements in array. Run a loop from 0 to N-1 (Where N is the total number of elements in array). Inside loop current array element is even then, increment the even count by 1. Otherwise increment the odd count. Print the values of even and odd count after the termination of loop. #include <stdio.h> #define maxsize 100 //Maximum size of the array int main() { int arr[maxsize]; int j, N, even, odd; /* Input size of the array */ printf("Enter size of the array: "); scanf("%d", &N); /* Input array elements */ printf("Enter %d elements in array: ", N); for(j=0; j<N; j++) { scanf("%d", &arr[j]); } /* Assuming that there are 0 even and odd elements */ even = 0; odd = 0; for(j=0; j<N; j++) { /* If the current element of array is even then increment even count */ if(arr[j]%2 == 0) { even++; } else { odd++; } } printf("Total even elements: %d\n", even); printf("Total odd elements: %d", odd); return 0; }