Program to count the number of even and odd elements in an array | faceprep

Program to count the number of even and odd elements in an array | faceprep

The program to count the number of even and odd elements in an array is discussed here. Given an array of integers, count the total number of odd elements and even elements in the array and display them as output.

Program to count the number of even and odd elements in an array


Input format:

  • Input consists of 1 integer and 1 array.
  • The integer corresponds to the size of an array.

Output format:

The output consists of integers

Sample Input:

3 (number of elements of the array)

1 (array elements)

2

3

Sample Output:

Odd: 2

Even: 1


face prep pro ad

Algorithm to count the number of even and odd elements in an array

  • Input the number of elements of the array.
  • Input the array elements.
  • Initialize count_odd = count_even = 0.
  • Traverse the array and increment count_odd if the array element is odd, else increment count_even.
  • Print count_odd and count_even.

Program to count the number of even and odd elements in an array

@@coding::1@@


Recommended Programs


Program to count the number of even and odd elements in an array

c