C Program to find the average of n numbers


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


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

Example: How to find the average of n numbers in c.

#include<stdio.h>

int main() {

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

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

   printf("Enter numbers :");

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

   average = sum / k;
   printf("The average is :%f", average);

   return 0;
}

Output:

How many numbers :5                                                                                                                                                 
Enter numbers :10 20 30 40 50                                                                                                                                       
The average is :30.000000