5. Write a C Program to calculate the Average of an array elements where the elements are
received as input.
#include <stdio.h>
int main()
{
int n,i;
float numbers[100];
float sum=0;
float average=0;
printf("Enter the number of elements: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter number %d: ", (i+1));
scanf("%f", &numbers[i]);
}
for (i = 0 ; i <n; i++)
{
sum+=numbers[i];
}
average=sum/(float)n;
printf("The average of an array elements %.2f\n", average);
getchar();
getchar();
return 0;
}
Comments
Leave a comment