Write a C Program to count even and odd numbers in an array

Admin

 

Write a C Program to count even and odd numbers in an array

#include<stdio.h>
#define SIZE 10
int main(void)
{
	int arr[SIZE],i,even=0,odd=0;
	for(i=0; i<SIZE; i++)
	{
		printf("Enter a value for arr[%d] : ",i);
		scanf("%d",&arr[i]);
		if(arr[i]%2 == 0)
			even++;
		else
			odd++;
	}
	printf("Even numbers=%d, Odd numbers=%d\n",even,odd);
	return 0;
}
Output
Enter a value for arr[0] : 11
Enter a value for arr[1] : 12
Enter a value for arr[2] : 13
Enter a value for arr[3] : 14
Enter a value for arr[4] : 15
Enter a value for arr[5] : 16
Enter a value for arr[6] : 17
Enter a value for arr[7] : 18
Enter a value for arr[8] : 19
Enter a value for arr[9] : 20
Even numbers=5, Odd numbers=5

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.