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

The following is a C program to count even and odd elements in the array:

Expected Output:

How it works

  • In line 10, we declare and initialize an array named arr.
  • In line 11, we declare and initialize variables even_count and odd_count, to store the count of even and odd elements respectively.
  • In line 14-27, we have for loop to iterate over the items in the array.
  • In line 17, we have an if statement to check for even number. If the condition evaluates to true, we increment the even_count by 1. Otherwise, the element is odd and we increment the odd_count by 1. The for loop terminates when we run out of elements in the array.
  • In lines 28 and 29, we print the value of even_count and odd_count using the print statement.

Recommended Reading:

Leave a Comment

%d bloggers like this: