C++ Program to Calculate arithmetic mean

In this program, you will learn to find the arithmetic mean of all the numbers entered by the user in C++.

What is an arithmetic mean?

The Sum of all of the numbers of a group, when divided by the number of items in that list is known as the Arithmetic Mean or Mean of the group. For example, the mean of the numbers 5, 7, 9 is 4 since 5 + 7 + 9 = 21 and 21 divided by 3 [there are three numbers] is 7.

How to calculate the arithmetic mean in C++?

To calculate the arithmetic mean of numbers in C++ programming, the user is asked to enter the number of integers. Get the number into the variable n.  and then ask to enter the integers to find and print the arithmetic mean. Get the entered n numbers into an array arr[50];
A for loop can be used to read the entered numbers into the array arr[50]. Set a value to get the sum of the entered n numbers sum. Initially, the value of the sum is set to 0.
for(i=0; i     {
        sum = sum+arr[i];

Now the sum of the entered numbers is stored in the variable sum, to find the arithmetic mean, divide the sum by the number of elements n.
armean = sum/n;
Display the result on the screen


Step 1: Call the header file iostream.

Step 2: Use the namespace std.

Step 3: Open the integer type main function; int main().

Step 4: Declare  integer type variables n, I and float type array arr[50], sum, armean;

Step 5: set the value of the variable sum to 0 initially;

Step 6: Ask the user to enter the number of elements;

Step 7: get the number to the variable n;

Step 8: Ask the user to enter the elements;

Step 9: Read the entered numbers into the array arr[50] by using a for loop;

Step 10: calculate the same by using the formula sum = sum + arr[i] within the for              loop;

Step 11: Calculate the arithmetic mean by using the equation sum/n;

Step 12: Get the result into the variable armean

Step 13: Display the result;

Step 14:Exit 

C++ Source Code

using namespace std;
int main()
    int n, i;
    float arr[50], sum=0, armean;
    cout<<"How many number, You want to enter ? ";
    cout<<"\nEnter "<<n<<" Number: ";
    for(i=0; i<n; i++)
        sum = sum+arr[i];
    armean = sum/n;
    cout<<"\nArithmetic Mean = "<<armean;
    return 0;


How many number, You want to enter ? 5
Enter 5 Number: 10
Arithmetic Mean = 30.4