A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to find average of three numbers
Q:

C program to find average of three numbers

belongs to collection: C programs - Basic C Programs

0

Write C program finds the average of three numbers provided by the user. In this program, the variables used are of type float instead of integer because average can be in fraction.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C program to find average of three numbers - Source code

#include<stdio.h>
 
int main()
 
{
 
     float a,b,c;
     float average=0;
 
     printf("Enter three numbers to find their average: \n");
     scanf("%f%f%f",&a,&b,&c);
 
     average =(a+b+c)/3.0; // formula to calculate average
                           // of three numbers.
 
     printf("\n Average of three numbers is \t %f",average);
 
     return 0;
 
}

Program Output

Case 1:

Enter three numbers to find their average:
56
34
78

 Average of three numbers is     56.000000


Case 2:

Enter three numbers to find their average:
568
673
237

 Average of three numbers is     492.666656

Program Explanation

1. This program first prompt the user to input three numbers whose average is required.

2. The user can even enter the decimal numbers/ fractional numbers as the data type of numbers is float.

3. The average is calculated using the mathematical formula (a+b+c)/3.0 and printed on the screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to add two integer numbers... >>
<< C program to check whether a number is positive or...