Skip to content
Home » C Program to Find Sum and Average of 3 Numbers

C Program to Find Sum and Average of 3 Numbers

Learn about C Program to Find Sum and Average of 3 Numbers in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program to Find Sum and Average of 3 Numbers

Explanation:

Three variables are specified in this programme: num1, num2, and num3. Three floating-point numbers will be stored in these variables.

The scanf function reads the numbers until the user enters all three numbers. By type promotion, if the user submits an integer number, it will be immediately converted to a floating-point value.

The total is computed as num1+num2+num3. Because the values of the three variables are all floating-point numbers, their sum will also be a floating-point number. The average is determined using the formula sum/ (total numbers).

The variables num1, num2, and num3 are printed after calculating the sum and average of the integers. Finally, the total and average are shown on the screen.

Source code:

#include<stdio.h>
int main()
{
  float num1, num2, num3;
  float sum, avg;

  // inputs from user
  printf("Enter three Numbers: ");
  scanf("%f %f %f",&num1, &num2, &num3);

  // calculating sum
  sum = num1 + num2 + num3;

  // calculate the average
  avg = sum / 3;

  printf("Entered numbers are: %.2f, %.2f and %.2f\n",
           num1, num2, num3);

  printf("Sum=%.2f\n", sum);
  printf("Average=%.2f\n",avg );

  return 0;
}

Output:

Enter three Numbers: 5 8 12
Entered numbers are: 5.00, 8.00 and 12.00
Sum=25.00
Average=8.33

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program to Compute Quotient and Remainder using fmod function
C Program to Compute Quotient and Remainder