C++ program to calculate the arithmetic mean

In this article, we will learn the C++ program to calculate the arithmetic mean. The arithmetic mean can be calculated by the sum of all the numbers divided by the total number count in a series.

For Example, if we have a series of numbers 3, 6, 9, 2, 1. Its arithmetic mean will be the 3+6+9+2+1/5 = 4.2

Program: Calculate the arithmetic mean in C++

//C++ program to calculate arithmetic mean
#include<iostream>
using namespace std;
int main()
{
        float arr[50], sum=0, mean=0; 
		int number, i; 
        cout<<"Enter total number in a series? ";
        cin>>number;
        cout<<"Enter "<<number<<" Numbers:\n";
        for(i=0; i<number; i++)
        {
                cin>>arr[i];
                sum=sum+arr[i];
        }
                mean=sum/number;
        cout<<"Arithmetic Mean = "<<mean;
        return 0;
}

Output


Recommended Articles

C++ Arrays

C++ Operators

Scroll to Top