C Program to Calculate the average of three numbers

Hey Coders !! Today we will understand the C Program to Calculate the average of three numbers.
There are two methods in which we can calculate the average of three numbers.
What is average of numbers?
In mathematics, the sum of all the numbers divided by the number count is called the average of numbers.
Average of numbers give us the center value that is generated with all the numbers.
1. First Method Of Program-
In this, we will define the value of variables in the program and will not ask the user to define the variables. This is the simplest way of calculating the average.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// C Program To Calculate the average of three numbers #include<stdio.h> int main() { int First=10; int second=40; int third= 34; int average,sum; printf("Calculating the Sum of three numbers"); sum = First+second+third; printf("Calculating the average"); average=sum/3; printf("The average of three numbers is %d",average); return 0; } |
1 2 3 |
<strong>Output -</strong> Calculating the sum of three numbers Calculating the average The average of three numbers is 28 |
In this method, we first calculate the sum of the three numbers and then divided the number by the number count. In this the number count is 23.
2. Second Method Of Program-
In this method, we will first ask the users to define the values of variables by themselves. The rest of the method is same for calculating the average of three numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> int main() { int First, second, third ; int average,sum; printf("Enter the value of three variables"); scanf("%d, %d, %d"&first,&second,&third); printf("Calculating the Sum of all numbers"); sum = First+second+third; printf("Calculating the average"); average=sum/3; printf("The average of three numbers is %d",average); return 0; } |
1 2 3 4 |
<strong>Output -</strong> Enter the value of three variables Calculating the sum of three numbers Calculating the average The average of three numbers is 28 |
I hope you all have completely understand the C Program To calculate the average of three numbers.
We daily add Multiple Choice Questions for placement preparation questions and technical interview preparation on the Instagram page. Check the Instagram account: Shout Coders
Frequently Asked Questions-
Yes, we can calculate the average of n numbers but for that, we should have the knowledge of arrays. Learn Arrays.
Yes, we can use functions to calculate the average of the three numbers
Yes, this is one of the simplest programs in programming languages and it also important from the point of an exam.