Write a C Program to calculate the Average of an array elements where the elements are received as input.
#include <stdio.h>
double Average(int a[], int size) {
int i, sum=0;
for (i=0; i<size; i++) {
sum += a[i];
}
return (double)sum / size;
}
int main() {
int arr[5];
double avg;
for (int i=0; i<5; i++) {
printf("Enter value for %d-th element: ", i+1);
scanf("%d", &arr[i]);
}
avg = Average(arr, 5);
printf("Average value is %.2lf\n", avg);
return 0;
}
Comments
Leave a comment