The mean is the average of the numbers. It is easy to calculate: add up all the numbers, then divide by how many numbers there are. In other words it is the sum divided by the count.
Example:- Average of 1,2,3,4,5 is (1+2+3+4+5)/5 = 3.
Example:- Average of 1,2,3,4,5 is (1+2+3+4+5)/5 = 3.
Program:-
#include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n, i;
float num[100], sum=0.0, average;
cout << "Enter the numbers of data: ";
cin >> n;
while (n > 100 || n <= 0)
{
cout << "Error! number should in range of (1 to 100)." << endl;
cout << "Enter the number again: ";
cin >> n;
}
for(i = 0; i < n; ++i)
{
cout << i + 1 << ". Enter number: ";
cin >> num[i];
sum += num[i];
}
average = sum / n;
cout << "Average = " << average;
getch();
}
Output:-
Output!!!!!!!1 |
0 Comments