question-. write a programme to accept 5 elements of integer array and display the sum and average of the elements
Answers
Answer:
here is your answer
Explanation:
#include <stdio.h>
int main() {
int n, i;
float num[100], sum = 0.0, avg;
printf("Enter the numbers of elements: ");
scanf("%d", &n);
while (n > 100 || n < 1) {
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}
for (i = 0; i < n; ++i) {
printf("%d. Enter number: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}
Answer:
hope this hepls
Explanation:
int main() {
int n, i;
float num[100], sum = 0.0, avg;
printf("Enter the numbers of elements: ");
scanf("%d", &n);
while (n > 100 || n < 1) {
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}
for (i = 0; i < n; ++i) {
printf("%d. Enter number: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}