C Program to find average of n numbers


In this program, You will learn how to find average of n numbers in C.


10 + 20 + 30 + 40 + 50 / 5 = 30.000000


Example: How to find average of n numbers in C

Run it Now
#include<stdio.h>

int main() {

   int k, n, sum = 0, i;
   float average;

   printf("How many Numbers :");
   scanf("%d", &k);

   printf("\nEnter Numbers :");

   for (i = 1; i <= k; i++) {
       scanf("%d", &n);
       sum = sum + n;
   }

   average = sum / k;
   printf("\nThe Average is :%f", average);

   return 0;
}

Output:

How many Numbers :5
Enter Numbers :10 20 30 40 50
The Average is :30.000000