WAP to take an Integer array with 5 elements and display average of all elements.
Answers
Answered by
1
Answer:
#include <stdio.h>
int main() {
int n, i;
float a[100], s = 0.0, avg;
printf("Enter the numbers of elements: ");
scanf("%d", &n);
while (n > 100 || n < 1) {
printf("Enter the number again: ");
scanf("%d", &n);
}
for (i = 0; i < n; ++i) {
printf("%d. Enter number: ", i + 1);
scanf("%f", &a[i]);
s += a[i];
}
avg = s / n;
printf("Average = %.2f", avg);
return 0;
}
Similar questions
Social Sciences,
22 days ago
Social Sciences,
22 days ago
Math,
22 days ago
Biology,
1 month ago
Physics,
8 months ago
History,
8 months ago
Math,
8 months ago