fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <vector>
  5.  
  6.  
  7. int main()
  8. {
  9. std::cout << "How many values do you want to enter?" << std::endl;
  10. unsigned n;
  11. std::cin >> n;
  12. std::vector<float> values(n);
  13. std::cout << "Enter " << n << " values:" << std::endl;
  14. std::copy_n(std::istream_iterator<float>(std::cin), n, values.begin());
  15. std::cout << "Average of values is " <<
  16. ( std::accumulate(values.begin(), values.end(), 0.0) / n ) << std::endl;
  17. auto minmax = std::minmax_element(values.begin(), values.end());
  18. std::cout << "Minimum is " << *minmax.first << std::endl;
  19. std::cout << "Maximum is " << *minmax.second << std::endl;
  20. std::cout << "Range is " << *minmax.second - *minmax. first;
  21. }
  22.  
Success #stdin #stdout 0s 3476KB
stdin
5
10.2 23.3 0.004 -12.65 1.158
stdout
How many values do you want to enter?
Enter 5 values:
Average of values is 4.4024
Minimum is -12.65
Maximum is 23.3
Range is 35.95