In this tutorial, we are going to learn a writing program in the C Programming language to find the Average of numbers.
This is How our program will behave
1). At first Our C Program will take the total count for the numbers for which we want to calculate the average.
2). After taking the count, We have to give the number to calculate the average.
3). Here we are considering input value as Integer and output may be an integer or float value.
What is the average number?
Average is a mathematical calculation that can be obtained by the sum of numbers divided by the total count of the numbers.
For example
Suppose we want to calculate the Average of 1,2,3,4,5
So, first, find the sum of all numbers
1+2+3+4+5 = 15
And here total count for the numbers is 5.
So Average will be 15/5 = 3
C Program to Calculate the average of numbers using for loop
#include<stdio.h>
void main() {
int n, i;
float num, average, sum = 0;
printf("Enter the value of n:");
scanf("%d", & n);
for (i = 1; i <= n; i++) {
printf("Enter the %d number: ", i);
scanf("%f", & num);
sum += num;
}
average = sum / n;
printf("\nTotal Average is = %1.2f\n ", average);
}
Output
C Program to calculate the average of numbers Using while loop
#include<stdio.h>
#include<conio.h>
void main() {
int n, i = 1;
float num, average, sum = 0;
printf("Enter the value of n:");
scanf("%d", &n);
while (i <= n) {
printf("Enter the %d number: ", i);
scanf("%f", &num);
sum += num;
i++;
}
average = sum / n;
printf("\nTotal Average is = %1.2f\n ", average);
}
Output 1:
[wpusb]
Also Prepare Below Important Question
- Sum of digits of Given Number in Java
- Hibernate Interview Questions for 2+ years of experience
- 68 Most Important Microservices Interview Questions
- 60 Most Important Git Interview Questions
- 50+ Mostly asked Java Interview Questions for 6 Years Exp.
- 60+ Mostly Asked Java Interview Questions for 4 Years Exp
- 60+ Mostly asked Java Interview Question for 3+ Years
- 60+ Spring Boot interview questions for 4+ years Exp.
- 60+ Mostly Asked Spring Boot Interview Questions for 3+ Yrs
- Scenario Based Java 8 Coding Interview Questions (For Experienced)
- Python Program to add two numbers without addition operator
- Mostly Asked Java Interview Questions For 2 Yrs Experience
- Find All Pairs in Array whose Sum is Equal to given number Using Java
- Java Program to find GCD of two Numbers using Recursion
- Python Program to Separate Characters in a Given String
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array
Interview Questions Categories
C Programming Interview Preparation
Core Java Programming Interview Preparation
- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions