Average of the numbers in C Program

How to write a c program to find the average of the number in c programming ?


Solution:
#include <stdio.h>

int main()
{
    int sum = 0;
    int n;
    int i = 0;

    while(scanf("%d", &n) != EOF)
    {
        sum += n;
        i++;
    }

    printf("Average is: %lf\n", sum*1.0 / i);

    return 0;
}


Learn More :