Here is a simple C++ program to find the mean value of a set of numbers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> #include <cstdlib> using namespace std; int main() { int num_count; double sum, mean; cout << "Enter the number of values: "; cin >> num_count; for (int i = 0; i < num_count; i++) { double num; cout << "Enter value " << i + 1 << ": "; cin >> num; sum += num; } mean = sum / num_count; cout << "The mean value is: " << mean << endl; return 0; } |
In this program, the computer ask the user to enter the desired. The program will calculate the mean of the given values. The program calculates the sum of values and divides the sum with the total number of values. After all, it will show the calculated mean value to the user.