Skip to content

C Program to Calculate the Average of Three Real Numbers

#include <stdio.h>

int main()
{
float num1, num2, num3, average;

printf(“Enter three real numbers: “);
scanf(“%f %f %f”, &num1, &num2, &num3);

average = (num1 + num2 + num3) / 3;

printf(“Average = %.2f”, average);

return 0;

}

Explanation

  • float is used to store real/decimal numbers.
  • scanf() takes three numbers from the user.
  • The average is calculated by adding the three numbers and dividing the sum by 3.
  • %.2f displays the answer up to 2 decimal places.