Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- int main(){
- int n = 0;
- std::cout << "Please insert a sequence of numbers! (an invalid input stops the request)" << std::endl;
- std::cout << "The average is: " << static_cast<double>(std::accumulate(std::istream_iterator<decltype(n)>(std::cin), std::istream_iterator<decltype(n)>(), 0, [&n](decltype(n) a, decltype(n) b){++n; return a + b;})) / std::max(n, 1) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment