/* Average of all elements of an array */
#include <stdio.h>
int main()
{
int n;
float av, sum = 0;
printf("Enter the number of elements of array: ");
scanf("%d", &n);
int a[n], i;
for(i = 0; i < n; i++){
printf("Enter element %d of array: ", i+1);
scanf("%d", &a[i]);
}
for(i = 0; i < n; i++){
sum += a[i];
}
av = sum/n;
printf("Average of all elements of the array = %1.4f", av);
return 0;
}
Comments
Post a Comment