To find the average of three numbers, we will use the formula to find the average.
Average of three number formula
Average = Sum/Count
Here Sum will be obtained by adding three numbers and instead of Count, it will be 3 because here we are taking the average of 3 numbers, if we take the average of 5 numbers, then 5 will come in place of Count.
C Program to Find the Average of Three Numbers (Simple Way)
Algorithm
Program Start
Declaring Variables
Input Three Numbers in Variables
Calculating Average of Three Numbers (average = sum/count)
Displaying the Average of Three Numbers
Program End
Program
//C Program to Find the Average of Three Numbers (Simple Way)
#include<stdio.h>
void main()
{
int x, y, z; //Declaring Three Variables
float avg;
printf("Enter Three Numbers : \n");
scanf("%d %d %d",&x, &y, &z); //Input Numbers
avg=(x+y+z)/3.0; //Calculating Average of three numbers
printf("Average of Three Numebers is : %f", avg);
}
Output
Enter Three Numbers :
10
2
38
Average of Three Numebers is : 16.666666
Program Explanation
In this program, we first declared three variables x, y, z.
After that created a variable named avg with the help of float data type
In this avg variable, we will store the average of the number three.
After declaring the variables, we got input three numbers from the user and store those values in the x, y, z variables.
After this, we Calculate the average of three numbers using the formula (average = sum/count) and stored its result in the avg variable.
Finally, we printed the stored value in this avg variable on the screen with the help of printf() function.
In this program, when we calculate the average of three numbers, we wrote 3.0 instead of 3, which means the same thing in maths.
C Program to Find the Average of Three Numbers Using Function
Algorithm
Program Start
Declaring variables
Input Numbers
Calling Function to find Average
Calculating Average
Print the Average of three Numbers
Program End
Program
//C Program to Find the Average of Three Numbers Using Function
#include<stdio.h>
void average(int,int, int);
void main()
{
int x, y, z; //Declaring Variables
printf("Enter Three Numbers : \n");
scanf("%d %d %d",&x, &y, &z); //Input Numbers
average(x,y,z); //Calling Function to find the Average of three numbers
}
void average(int a,int b, int c)
{
float avg;
avg=(a+b+c)/3.0;
printf("Average of Three Numebers is : %f", avg);
}
Output
Enter Three Numbers :
10
38
23
Average of Three Numebers is : 23.666666
C Program to Find the Average of Three Numbers Using Array
Algorithm
Program Start
Declaring variables
Input Numbers
Calculating Sum
Calculating Average
Print the Average of three Numbers
Program End
Program
//C Program to Find the Average of Three Numbers Using Array
#include<stdio.h>
void main()
{
//Declaring Variables
int i, sum = 0, a[3];
float avg;
printf("Enter Three Numbers : \n");
for(i=0; i<3; i++)
{
scanf("%d",&a[i]); //Input Numbers
}
for(i=0; i<3;i++)
{
sum = sum + a[i]; //Input Numbers
}
avg=sum/3.0;
printf("Average of Three Numebers is : %f", avg);
}
Output
Enter Three Numbers :
38
23
38
Average of Three Numebers is : 33.000000
C Program to Find the Average of Three Numbers
To find the average of three numbers, we will use the formula to find the average.
Average of three number formula
Average = Sum/Count
Here Sum will be obtained by adding three numbers and instead of Count, it will be 3 because here we are taking the average of 3 numbers, if we take the average of 5 numbers, then 5 will come in place of Count.
C Program to Find the Average of Three Numbers (Simple Way)
Algorithm
Program
Output
Program Explanation
C Program to Find the Average of Three Numbers Using Function
Algorithm
Program
Output
C Program to Find the Average of Three Numbers Using Array
Algorithm
Program
Output
need an explanation for this answer? contact us directly to get an explanation for this answer