C program to find sum and average of given 3 numbers

C program to find sum and average of given 3 numbers

C program to find sum and average of 3 and 5 numbers; In this tutorial, you will learn how to find sum and average of 3 and 5 numbers in c.

Algorithm and Programs to Find Sum and Average of 3, 5 Number in C

Let’s use the following algorithm and program to print sum and average of 3 numbers in c:

  • Algorithm of find sum and average of three or five numbers
  • C Program to Find Sum and Average of 3 Number
  • C Program to Find Sum and Average of 5 Number

Algorithm of find sum and average of three or 5 numbers

  • Step 1: Start
  • Step 2: Read the three or five numbers from the user.
  • Step 3: Declared a variables “Avg” and “Sum”.
  • Step 4: Calculate sum and average of 3 or 5 numbers using the followig formulas:
    • sum = (a+b+c);
    • avg = (a+b+c)/3;
    • sum = (a+b+c+e+f);
    • avg = (a+b+c+e+f)/3;
  • Step 5:Display “sum ” and “Avg”.
  • Step 6:End.

C Program to Find Sum and Average of 3 Number

#include<stdio.h>
 
int main()
 
{
 
  float a,b,c,avg,sum;
 
  printf("Please enter 3 numbers ");
 
  scanf("%f%f%f", &a, &b, &c);
 
  sum=(a+b+c);
  avg=sum/3;
 
 
  printf("\Sum is  %f",sum);
  printf("\nAverage is  %f",avg);
 
  return 0;
 
}

The output of the above c program; as follows:

Please enter 3 numbers 1 2 3
Sum is  6.000000
Average is  2.000000

C Program to Find Sum and Average of 5 Number

#include<stdio.h>

int main() {

   float a, b, c, d, e, s, avg;

   printf("Please Enter 5 Numbers :");
   scanf("%f%f%f%f%f", &a, &b, &c, &d, &e);

   s = a + b + c + d + e;

   avg = s / 5;

   printf("\nThe Sum is :%f", s);
   printf("\nThe Average is :%f", avg);

   return 0;
}

The output of the above c program; as follows:

Please Enter 5 Numbers :1 2 3 4 5
The Sum is :15.000000
The Average is :3.000000

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 *