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