Q:

Write a C++ Program to Calculate Arithmetic Mean of N numbers

belongs to collection: C++ Number Solved Programs

0

Write a C++ Program to Calculate Arithmetic Mean of N numbers. Here’s simple C++ Program to Calculate Arithmetic Mean of N numbers in C++ Programming Language

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Normally, when we work with Numbers, we use primitive data types such as int, short, long, float and double, etc. The number data types, their possible values and number ranges have been explained while discussing C++ Data Types.

 
 

To calculate arithmetic mean of numbers in C++ Programming, you have to ask to the user to enter number size then ask to enter the numbers of that size.

To calculate arithmetic mean of all numbers, first perform addition of all the numbers, then make a variable responsible for the arithmetic mean and place addition/size in a variable say armean (arithmetic mean), then display the result.


Here is source code of the C++ Program to Calculate Arithmetic Mean of N numbers. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.

 

SOURCE CODE : :

/*  C++ Program to Calculate Arithmetic Mean of N numbers  */

#include<iostream>
using namespace std;

int main()
{
        int n, i, arr[50], sum=0;
        cout<<"\nHow many number you want to enter :: ";
        cin>>n;

        cout<<"\nEnter "<<n<<" Numbers Below :: \n";
        for(i=0; i<n; i++)
        {
            cout<<"\nEnter [ "<<i+1<<" ] Number :: ";
                cin>>arr[i];
                sum=sum+arr[i];
        }

        int armean=sum/n;

        cout<<"\nArithmetic Mean of [ "<<n<<" ] Numbers = "<<armean<<"\n";

        return 0;
}

OUTPUT : :


/*  C++ Program to Calculate Arithmetic Mean of N numbers  */

How many number you want to enter :: 5

Enter 5 Numbers Below ::

Enter [ 1 ] Number :: 1

Enter [ 2 ] Number :: 2

Enter [ 3 ] Number :: 3

Enter [ 4 ] Number :: 4

Enter [ 5 ] Number :: 5

Arithmetic Mean of [ 5 ] Numbers = 3

Process returned 0

Above is the source code for C++ Program to Calculate Arithmetic Mean of N numbers which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Number Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Program to calculate Average of 5 subjects and... >>
<< C++ Program to Find Grade of a Student using if el...