fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <numeric>
  4. #include <iterator>
  5.  
  6. using namespace std;
  7.  
  8. template<typename T>
  9. T SumOfSqr(T sum, T a)
  10. {
  11. return sum + a*a;
  12. }
  13.  
  14. template<typename It1>
  15. double rms2(It1 b, It1 e){
  16. typedef typename std::iterator_traits<It1>::value_type valueType;
  17. valueType sum = std::accumulate(b, e, valueType(), SumOfSqr<valueType>);
  18. return sqrt(sum*0.5);
  19. }
  20.  
  21. int main() {
  22. std::istream_iterator<int> eos;
  23. std::istream_iterator<int> it (std::cin);
  24.  
  25. cout << rms2(it, eos) << endl;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3472KB
stdin
2
3
4
stdout
3.80789