C Program to Read 10 Numbers and Find their Sum and Average

Write a C program to read 10 numbers and find their sum and average using for loop. In this example, for loop iterate from 1 to 10, add each number to the sum to find the sum of 10 numbers. Next, we calculate the average.

#include <stdio.h>

int main()
{   
    int num, sum = 0;
    float avg;
    
    printf("Please Enter the 10 Numbers\n");
    for(int i = 1; i <= 10; i++)
    {
        printf("Number %d = ", i);
        scanf("%d", &num);
        sum = sum + num;
    }

    avg = sum / 10;

    printf("\nThe Sum of 10 Numbers     = %d", sum); 
    printf("\nThe Average of 10 Numbers = %.2f\n", avg);
}
C Program to Read 10 Numbers and Find their Sum and Average

This C program reads 10 numbers from the user input and calculates their sum and average using a while loop.

#include <stdio.h>

int main()
{   
    int num, i, sum = 0;
    float avg;
    
    printf("Please Enter the 10 Numbers\n");
    i = 1;

    while(i <= 10)
    {
        printf("Number %d = ", i);
        scanf("%d", &num);
        sum = sum + num;
        i++;
    }

    avg = (float)sum / 10.0;

    printf("\nThe Sum of 10 Numbers     = %d", sum); 
    printf("\nThe Average of 10 Numbers = %.2f\n", avg);
}
Please Enter the 10 Numbers
Number 1 = 22
Number 2 = 33
Number 3 = 44
Number 4 = 55
Number 5 = 67
Number 6 = 89
Number 7 = 123
Number 8 = 234
Number 9 = 543
Number 10 = 199

The Sum of 10 Numbers     = 1409
The Average of 10 Numbers = 140.90

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.