C Program to find average of numbers in an array


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


flaot average = 10 + 20 + 30 + 40 + 50 / 5


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

Run it Now
#include<stdio.h>

int main() {

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

  printf("Enter Size of Array :");
  scanf("%d",&n);

  printf("\nEnter Array Elements :");

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

  return 0;
}

Output:

Enter Size of Array :5
Enter Array Elements :10 20 30 40 50
The Average is :30.000000