C Program to Count Even & Odd Number in Array

Question: Write a program in C to read an array containing n positive integer numbers and count odd and even numbers.

Counting Even and Odd in Array


#include<stdio.h>
	
int main()
{
 int num[100], i, n, odd=0, even=0;
 clrscr();
 printf("Enter n: ");
 scanf("%d", &n);
 /* Reading array */
 printf("Enter numbers:\n");
 for(i=0; i< n ; i++)
 {
  printf("num[%d] = ", i);
  scanf("%d", &num[i]);
 }
 /* Counting Odd and Even */
 for(i=0; i< n ; i++)
 {
  if(num[i]%2 == 0)
  {
   even = even + 1;
  }
  else
  {
   odd = odd + 1;
  }
 }
 
 /* Displaying Result */
 printf("Even Count = %d\n", even);
 printf("Odd Count = %d", odd);
 return 0;
}

Output

Enter n: 9↲
Enter numbers:
num[0] = 21↲
num[1] = 11↲
num[2] = 13↲
num[3] = 12↲
num[4] = 33↲
num[5] = 22↲
num[6] = 67↲
num[7] = 76↲
num[8] = 88↲
Even Count = 4
Odd Count = 5