fork(1) download
  1. #include <iostream>
  2.  
  3. void Print1(int a, int b)
  4. {
  5. while(a < b)
  6. std::cout << a++ << ' ';
  7. while(a > b)
  8. std::cout << a-- << ' ';
  9. std::cout << a << std::endl;
  10. }
  11. void Print2(int a, int b)
  12. {
  13. int incr = 1 - 2 * ((b - a) < 0);
  14. while(a != b)
  15. {
  16. std::cout << a << ' ';
  17. a += incr;
  18. }
  19. std::cout << a << std::endl;
  20. }
  21.  
  22. int main()
  23. {
  24. int a, b;
  25. std::cin >> a >> b;
  26. Print1(a, b);
  27. Print2(a, b);
  28. return 0;
  29. }
Success #stdin #stdout 0s 3472KB
stdin
1 10
stdout
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10