using accumulate and vectors is pretty neat also:
Code:int num;
vector<int> nums;
while (cin >> num ) nums.push_back(num);
double avg = accumulate( nums.begin(), nums.end(), 0.0 ) / nums.size();
Printable View
using accumulate and vectors is pretty neat also:
Code:int num;
vector<int> nums;
while (cin >> num ) nums.push_back(num);
double avg = accumulate( nums.begin(), nums.end(), 0.0 ) / nums.size();
It is pretty much what Neo1 suggested, and just as wasteful if the only thing needed is to compute the arithmetic mean.Quote:
using accumulate and vectors is pretty neat also:
If i needed to find the mean, I wouldn't have used that code...
just something interesting to learn about. :)