fork download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <numeric>
  6.  
  7. std::vector<int> gAverage = {3,2,1,0};
  8. double average;
  9.  
  10. using namespace std;
  11.  
  12. void lAverage()
  13. {
  14. if (gAverage.size() >= 2)
  15. {
  16. auto itLast = gAverage.end() - 2;
  17. cout << endl << "The average of: ";
  18. copy(gAverage.begin(), itLast, ostream_iterator<int>(cout, ","));
  19. cout << *itLast << " = " << average << endl;
  20. }
  21. }
  22.  
  23. int main()
  24. {
  25. average = std::accumulate(gAverage.begin(), gAverage.end() - 1, 0) / (double)(gAverage.size() - 1);
  26. lAverage();
  27. }
  28.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
The average of: 3,2,1 = 2