Twenty-five numbers are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are even and how many odd.
void main()
{
int arr[25];
int a,b,c,d,e,i;
a=0;
b=0;
c=0;
d=0;
e=0;
for(i=0;i<25;i++)
{
printf("\nKey the %d) value",i);
scanf("%d",&arr[i]);
}
for(i=0;i<25;i++)
{
if(arr[i]>0)
a++;
if(arr[i]<0)
b++;
if(arr[i]==0)
c++;
if(arr[i]%2==0)
d++;
else
e++;
}
if(a>0)
printf("\nThere are %d positive integers",a);
if(b>0)
printf("\nThere are %d negative integers",b);
if(c>0)
printf("\nThere are %d zeros",c);
if(d>0)
printf("\nThere are %d even numbers",d);
if(e>0)
printf("\nThere are %d odd numbers",e);
}
Subscribe to:
Post Comments (Atom)
A number might be positive as well as even, but using this code i dont think it would be counted in both...
ReplyDelete--shubham
the code is fine dude ..
ReplyDeletevalue of even numbers always =25 !!
ReplyDeleteNot Working
ReplyDelete