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

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.