fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <class fwdit>
  5. typename fwdit::value_type arithmetic_mean(fwdit begin, fwdit end) {
  6.  
  7. typedef typename fwdit::value_type res_type;
  8.  
  9. res_type sum = res_type();
  10. size_t count = 0;
  11.  
  12. for (fwdit pos = begin; pos!= end; ++pos) {
  13. sum += *pos;
  14. ++count;
  15. }
  16. return sum/count;
  17. }
  18.  
  19. int main() {
  20. std::vector< int> vi( 10, 3);
  21. vi[9] = 5;
  22. double average = arithmetic_mean( vi.begin(), vi.end());
  23. std::cout << average;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
3