Find average of array value by R4R Team

Example-
Array is: [1,2,3,4,5]
Average is: 3

program-

#include< stdio.h>
int main()
{
int a[20],n,i;
float sum=0;
float avg;
printf("Enter number of elements in array\n");
scanf("%d",&n);
printf("Enter %d number in array\n",n);
//input in array
for(i=0;i< n;i++)
scanf("%d",&a[i]);
//Now find the average
for(i=0;i< n;i++){
sum=sum+a[i];
}
avg=sum/n;
printf("Average is %f",avg);
}


output-

Enter number of elements in array
6
Enter 6 number in array
1 2 3 4 5 6
Average is 3.500000

-In this program, firstly we take an input in array then for finding the average, we find the sum of all elements and divide by the totaol number of element.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!