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

In this tutorial, i am going to show you how to find sum and average of 10 numbers in the c program using for loop and while loop.

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

  • Algorithm to Read 10 Numbers and Find their Sum and Average
  • C Program to Read 10 Numbers and Find their Sum and Average using For Loop
  • C Program to Read 10 Numbers and Find their Sum and Average using While Loop

Algorithm to Read 10 Numbers and Find their Sum and Average

Follow the below given algorithm to write a program to read 10 numbers from keyboard and find their sum and average:

  • Step 1: Start Program.
  • Step 2: Read the 10 numbers from the user and store them in a variable.
  • Step 3: Calculate sum and average of 10 numbers using for loop or while loop.
  • Step 4: Print sum and average 10 number.
  • Step 5: Stop Program.

C Program to Read 10 Numbers and Find their Sum and Average using For Loop

#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);
}

The result of the above c program; as follows:

Please Enter the 10 Numbers
Number 1 = 10
Number 2 = 20
Number 3 = 30
Number 4 = 40
Number 5 = 50
Number 6 = 60
Number 7 = 70
Number 8 = 80
Number 9 = 90
Number 10 = 100
The Sum of 10 Numbers     = 550
The Average of 10 Numbers = 55.00

C Program to Read 10 Numbers and Find their Sum and Average using 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);
}

The result of the above c program; as follows:

Please Enter the 10 Numbers
Number 1 = 10
Number 2 = 20
Number 3 = 30
Number 4 = 40
Number 5 = 50
Number 6 = 60
Number 7 = 70
Number 8 = 80
Number 9 = 90
Number 10 = 100
The Sum of 10 Numbers     = 550
The Average of 10 Numbers = 55.00

Be First to Comment

Leave a Reply

Your email address will not be published.