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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.