In this tutorial you will learn about the C Program to Calculate Arithmetic Mean and its application with practical example.
C Program to Calculate Arithmetic Mean
In this tutorial, we will learn to create a C program that will Calculate Arithmetic Mean using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C Programming.
- For Loop in C programming.
Program to Calculate Arithmetic Mean
In c programming, it is possible to take numerical input from the user and Calculate the Arithmetic Mean with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them. With the help of these functions, the programming is easy.
With the help of this program, we can Calculate Arithmetic Mean.
Here,
We will first take the input
The second will make Calculate the Arithmetic Mean.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variables for the program. 2. Taking the input numbers from the user. 3. Passing those numbers to the arithmetic operations. 4. Calculating the mean of the numbers. 5. Printing the result number. 6. End Program. |
Program to Calculate Arithmetic Mean:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<stdio.h> int main() { //declaring the variable for the program int i, size; float num, sum, am; //taking input from the user number of elements printf("How many number to enter ? "); scanf("%d", &size); sum = 0; //taking input from the user elements for mean printf("Enter %d Numbers: ", size); //Calculating the arithmetic mean for(i=0; i<size; i++) { scanf("%f", &num); sum = sum+num; } am = sum/size; //printing the output for the calculations done above printf("\nArithmetic Mean = %0.2f", am); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- size = it will hold the integer value.
- i = it will hold the integer value.
- num = it will hold the float value.
- sum = it will hold the float value.
- am = it will hold the float value.
Input number from the user.
Program Logic Code.
Printing the output.