#include <stdio.h>
//to count pos,neg,odd,even, numbers in an array
int main()
{
int num[10],i,pos=0,neg=0,odd=0,even=0;
printf("\n Enter the Elements of the Array :");
for(i=0;i<=9;i++)
scanf("%d", &num[i]);
for(i=0;i<=9;i++)
{
num[i]<0?neg++:(pos++); //Conditional Operators
num[i]%2?odd++:(even++);
}
printf("\n Negative Numbers %d", neg);
printf("\n Positive Numbers %d", pos);
printf("\n Odd Numbers %d", odd);
printf("\n Even Numbers %d", even);
return 0;
}
Comments
Post a Comment