C Program To Find Average of N Numbers
Learn How to Find Average of N Numbers in C Programming. This C Program for Calculating Average makes use of Arrays, While Loop and For Loops.
Method 1: C Program To Find Average of N Numbers using Arrays
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<stdio.h> int main() { int arr[50], limit, average, count, sum = 0; printf("\nEnter Total Number of Elements To Insert in Array:\t"); scanf("%d", &limit); for(count = 0; count < limit; count++) { printf("Enter Element No. %d\t", count + 1); scanf("%d", &arr[count]); } for(count = 0; count < limit; count++) { sum = sum + arr[count]; average = sum / limit; } printf("\nAverage of Array Elements:\t%d\n", average); return 0; } |
Method 2: C Program To Calculate Average of Numbers without Arrays
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<stdio.h> int main() { int limit, number, average, count, sum = 0; printf("\nEnter Total Number of Elements:\t"); scanf("%d", &limit); for(count = 0; count < limit; count++) { printf("Enter Element No. %d\t", count + 1); scanf("%d", &number); sum = sum + number; } average = sum / limit; printf("\nAverage of N Numbers:\t%d\n", average); return 0; } |
Method 3: C Program To Calculate Average of Integers using While Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<stdio.h> int main() { int limit, number, average, count, sum = 0; printf("\nEnter Total Number of Elements:\t"); scanf("%d", &limit); count = 0; while(count < limit) { printf("Enter Element No. %d\t", count + 1); scanf("%d", &number); sum = sum + number; count++; } average = sum / limit; printf("\nAverage of N Numbers:\t%d\n", average); return 0; } |
Output

If you have any compilation error or doubts in this C Program To Calculate Average of N Numbers, let us know about it in the Comment Section below.
You have taken the limit of the Array as 50. What if the User inputs elements more than 50? What is the solution to this?
You may either use a Macro Definition and define the Limit as 100 or you can take the Array Dimension/Size as 200 and then take the limit from the User.
Such a good brief explanation about finding average of n numbers in c programming. Thanks.
I think finding averga of n numbers using array is much better than finding of n numbers using For loop or While loop. Arrays helps to manage memory better and also makes elements easily accessible.
It is better to store elements in an array than to calculate average of numbers in c programming.