C Program to Calculate Arithmetic Mean

« Previous Program Next Program »

In this article, you will learn and get code about how to find arithmetic mean of given list of number by user (at run-time).

How Arithmetic Mean gets Calculated ?

To calculate arithmetic mean, use the formula mean = (n1+n2+n2+...+nn)/n. Here n1 represents first number, n2 represents second number and so on. Whereas, n (in denominator part) is a value that represents the quantity of number. For example, if there are three numbers say 3, 5, 8. So to find its arithmetic mean, use the formula as given earlier. Therefore, arithmetic mean of 3, 5, 8 will be (3+5+8)/3 or 16/3 or 5.33.

Arithmetic Mean Program in C

To calculate arithmetic mean in C programming, you have to ask from user to enter, how many numbers he/she want to provide (quantity) say 3. Then ask to enter all the numbers (say 3, 5, 8) of that size (3). Now apply the simple formula of finding arithmetic mean as shown here in the following program:

// Arithmetic Mean Program in C

int main()
    int i, size;
    float num, sum, am;
    printf("How many number to enter ? ");
    scanf("%d", &size);
    sum = 0;
    printf("Enter %d Numbers: ", size);
    for(i=0; i<size; i++)
        scanf("%f", &num);
        sum = sum+num;
    am = sum/size;
    printf("\nArithmetic Mean = %0.2f", am);
    return 0;

This program is compiled and executed using Code::Blocks IDE. Here is the sample run of above program:

c program arithmetic mean

Now supply the size (how many number user want to enter to find arithmetic mean of these entered numbers) say 3. Then enter all the 3 numbers say 3, 5, 8 and finally press ENTER key to see the output as shown in the snapshot given below:

arithmetic mean program c

Steps used in previous Program

Here are the list of some main steps used in above program:

Same Program in Other Languages

« Previous Program Next Program »