fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. void arrange(std::vector<double>& result, double min, double max, double step)
  7. {
  8. result.clear();
  9. if (max < min || step <= 0.0)
  10. return;
  11.  
  12. size_t n = static_cast<size_t>((max-min) / step);// + 1;
  13. double acc = min;
  14. //std::generate_n(std::back_inserter(result), n, [&](){ double t = acc; acc += step; return t; });
  15. for(int i = 0; i < n; i++)
  16. {
  17. result.push_back(acc);
  18. acc += step;
  19. }
  20.  
  21. }
  22.  
  23. int main() {
  24. std::vector<double> res;
  25. arrange(res, 10, 20, 1);
  26. for(auto &e : res)
  27. {
  28. std::cout << e << " ";
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
10 11 12 13 14 15 16 17 18 19