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

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

C program to read 10 numbers and find sum and average; Through this tutorial, we will learn how to find sum and average of 10 numbers in the c program with the help for loop and while loop.

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

Use the following algorithm and program to read 10 numbers from keyboard and find their sum and average using for loop and while loop 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

Use the following algorithm to write a program to read 10 numbers from keyboard and find their sum and average; as follows:

  • 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 output 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 output 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

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *