C Program to print count of even and odd numbers in array

Category: C ProgramTags: array cprogram

C Program to print the count of even and odd numbers in an array.

C Program to print count of odd and even numbers in array

#include <stdio.h>

void main()
{
    int arr[50], n, i, even = 0, odd = 0;

    printf("Enter number of elements: ");
    scanf("%d", &n);

    printf("Enter array elements-\n");
    for (i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    for (i = 0; i < n; i++)
    {
        if (arr[i] % 2 == 0)
            even++;
        else
            odd++;
    }

    printf("\nCount of even numbers: %d\n", even);
    printf("Count of odd numbers: %d", odd);
}

Output

Output

Enter number of elements: 5
Enter array elements-
2
3
1
4
5
Count of even numbers: 2
Count of odd numbers: 3