Friday, October 30, 2009

Chap8[D]b Finding +tive -tive zeros, odd and even numbers in array

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);

}

4 comments:

  1. A number might be positive as well as even, but using this code i dont think it would be counted in both...

    --shubham

    ReplyDelete
  2. the code is fine dude ..

    ReplyDelete
  3. value of even numbers always =25 !!

    ReplyDelete