Find average of three numbers - C Program

C program to read three numbers and find average of numbers.

Solution:

#include <stdio.h>
int main()
{
      int a,b,c;
      float avg;
      printf("\tEnter Three Numbers\n");
      printf("--------------------------------\n");
      printf("Enter First Number  : ");
      scanf("%d", &a);
      printf("\nEnter Second Number : ");
      scanf("%d",&b);
      printf("\nEnter Third Number : ");
      scanf("%d",&c);
      printf("--------------------------------\n");
      /* To find average*/
      avg=a+b+c/3.0;
      printf("\nAverage of Three Numbers : %f",avg);
      return 0;
}


Output:

average three no

In the above output, we can fix the digit after decimal points while printing an average of three numbers. If we want to fix 2 digits after decimal point, then we can use (.2) in the following statement.

printf("\nAverage of Three Numbers : %.2f",avg);

Following is the output after writing above statement in program.

average three no