NUMBER OF ODD AND EVEN NUMBERS IN AN ARRAY
Consider the following I/O samples.
SAMPLE INPUT: 1 2 3 4 5 6 7 8 9 10
#include<stdio.h>
int main()
{
int arr[100];
int i, n,even=0,odd=0;
printf("Enter the number of elements:");
scanf("%d",&n);
printf("Enter the array elements:");
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("ODD = %d\nEVEN = %d",odd,even);
return 0;
}

The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
SAMPLE OUTPUT: ODD = 5
EVEN = 5
C PROGRAM:
#include<stdio.h>
int main()
{
int arr[100];
int i, n,even=0,odd=0;
printf("Enter the number of elements:");
scanf("%d",&n);
printf("Enter the array elements:");
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("ODD = %d\nEVEN = %d",odd,even);
return 0;
}
OUTPUT:

The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment