Monday, January 4, 2010

Program to show sum of 10 elements of array & show the average.

 #include
#include

void main()
{

int a[10],i,sum=0;
float av;
clrscr();
printf("enter elements of an aaray: ");

for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
sum=sum+a[i];

printf("sum=%d",sum);
av=sum/10;
printf(“average=%.2f”,av);
getch();
}

 


Output:
enter elements of an array: 4
5
6
1
2
3
5
5
4
7

sum=42
average=4.22

No comments:

Post a Comment