Finding the Mean Value
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main( )
{
// miles per gallon for different cars in fleet
const float mpg_data[] = { 1.1, 9.9, 8.8, 3.3, 2.2, 2.2,4.4 };
// create a vector and initialize it with the above data
vector<float> mpg( mpg_data,mpg_data + sizeof( mpg_data ) / sizeof( mpg_data[0] ) );
// mean
float fleet_average = accumulate( mpg.begin(), mpg.end(), 0.0 )/ mpg.size();
cout << fleet_average << endl;
}
Related examples in the same category