C program to accept 10 elements in an array and count how many even and odd numbers are there

Example#1

#include<stdio.h>
int main()
{
	int n,i,a[30],count1=0,count2=0;
	printf("Enter the size of array:");
	scanf("%d",&n);
	printf("\nEnter the array elements:");
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	printf("\nElements are:");
	for(i=0;i<n;i++)
	{
		printf("%d ",a[i]);
	}
	for(i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			count1++;
		}
		else
		{
			count2++;
		}
	}
	printf("\nNumber of Even numbers:%d",count1);
	printf("\nNumber of Odd numbers:%d",count2);
	return 0;
}

Output:

Facebook Comments

Back to Top