Computer Science, asked by swapnilmukherjee04, 1 month ago

WAP to take an Integer array with 5 elements and display average of all elements.​

Answers

Answered by sakshijn
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