Write a C program to count and display positive, negative, odd and even numbers in an array.
Program Code:
#include<stdio.h>
void main()
{
int a[10],i,o=0,p=0,e=0,n=0;
printf(" enter 10 nos\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{
if(a[i]%2==0)
{
e++;
}
else
{
o++;
}
if(a[i]>=0)
{
p++;
}
else
{
n++;
}
}
printf("\n even nos.=%d",e);
printf("\n odd nos.=%d",o);
printf("\n +ve nos.=%d",p);
printf("\n -ve nos.=%d",n);
}
}
Post A Comment:
0 comments: