Print the number of Odd & Even numbers in an array

Write a program to print the number of Odd & Even numbers in an array.


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
	int i,z,a[20],p=0,c=0;
	clrscr();
	printf("Enter the size of array : ");
	scanf("%d",&z);
	printf("Enter the array elements : \n");
	for(i=0;i<z;i++)
	{
		scanf("%d",&a[i]);
	}
	printf("The array elements are : \n");
	for(i=0;i<z;i++)
	{
		printf("%d\n",a[i]);
	}
	for(i=0;i<z;i++)
	{
		if(a[i]%2==0)
		{
			c++;
		}
		else
		{
			p++;
		}
	}
	printf("No. of Even : %d\n",c);
	printf("No. of Odd : %d",p);
	getch();
}



Output:

Enter size of array: 4
Enter array elements:
1
2
3
4 

The array elements are:
1
2
3
4

No. of even: 2
No. of odd: 2

Leave a Reply

Your email address will not be published. Required fields are marked *