C PROGRAMMING

write a c program to calculate average of array elements

#include <stdio.h>
main() {
int n, i, num[100];
float sum = 0.0, avg;
printf("Enter the size array : n");
scanf("%d", &n);
for (i = 0; i < n; ++i) {
printf("Enter %d number : ", i + 1);
scanf("%d", &num[i]);
sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
getch();
}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button