programming-examples/c++/Others/Accumulate value in a vector.cpp

32 lines
605 B
C++
Raw Normal View History

2019-11-15 12:59:38 +01:00
Accumulate value in a vector
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
double arithmeticMean(const vector<int>& nums)
{
double sum = accumulate(nums.begin(), nums.end(), 0);
return (sum / nums.size());
}
int product(int num1, int num2)
{
return (num1 * num2);
}
int main(int argc, char** argv)
{
vector<int> myVector;
myVector.push_back(1);
myVector.push_back(2);
myVector.push_back(3);
myVector.push_back(4);
cout << "The arithmetic mean is " << arithmeticMean(myVector) << endl;
return (0);
}