Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

25 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 & how many odd.


Source Code :

#include<stdio.h>
void main()
{
      int a[25],odd=0,even=0,neg=0,pos=0,i;
      clrscr();
      printf("\nEnter 25 Elements : ");
      for(i=0;i<25;i++)
            scanf("%d",&a[i]);
      for(i=0;i<25;i++)
      {
            if(a[i]>=0)
                  pos++;
            else
                  neg++;
            if(a[i]%2==0)
                  even++;
            else
                  odd++;
      }
      printf("\nPositive : %d",pos);
      printf("\nNegative : %d",neg);
      printf("\nEven     : %d",even);
      printf("\nOdd      : %d",odd);
      getch();
}

Output :

Enter 25 Elements : 2 5 4 -5 0 7 8 -9 -4 1 -1 3 0 -7 -3 -5 8 7 9 1 7 -4 -7 6 -2

Positive : 15
Negative : 10
Even      : 10
Odd      : 15

No comments:

Post a Comment