C Program to find the average of numbers in an array


In this program, You will learn how to find the average of numbers in an array in c.


sum = 10 + 20 + 30 + 40 + 50

avg = sum/5

Example: How to find the average of numbers in an array in c

#include<stdio.h>
int main() {

  int arr[10],n,i,sum=0;
  float average;

  printf("Enter size of array:");
  scanf("%d",&n);

  printf("Enter array elements:");

  for (i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
      sum = sum + arr[i];
  }
  average = sum / n;
  printf("Average is:%f", average);

  return 0;
}

Output:

Enter size of array:5
Enter array elements:2 3 4 5 6
Average is:4.000000