9.25.2011

Even/Odd sum,average

/*
program for read 10 numbers and calculate even sum,odd sum,even average and odd average.
variable's name stands for as : 
es=even sum, ea=even average, ec=even count
os=odd sum, oa=odd average, oc=odd count
*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int arr[15];  
 int i;
 int es=0,ea,ec=0;
 int os=0,oa,oc=0;
 for(i=1; i<=10; i++)
 {
  printf("Enter %d number : ",i);
  scanf("%d",&arr[i]);
 }
 for(i=1; i<=10; i++)
 {
   if(arr[i]%2==0)
   {
      ec++;
      es=es+arr[i];
   }
   else
   {
      oc++;
      os=os+arr[i];
   }
 }
 ea=es/ec;
 oa=os/oc;
 printf("\nEven sum = %d",es);
 printf("\nEven average = %d",ea);
 printf("\nOdd sum = %d",os);
 printf("\nOdd Average = %d",oa);
 getch();
 return 0;
}

       Output of above program :

Enter 1 number : 1
Enter 2 number : 3
Enter 3 number : 5
Enter 4 number : 7
Enter 5 number : 9
Enter 6 number : 2
Enter 7 number : 4
Enter 8 number : 6
Enter 9 number : 8
Enter 10 number : 10

Even sum = 30
Even average = 6
Odd sum = 25
Odd Average = 5

No comments:

Post a Comment