fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. try
  7. {
  8. // declaration + definition
  9. int swapHolder = 0;
  10. const int ARRAY_SIZE = 12;
  11. int list[ARRAY_SIZE] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 };
  12.  
  13. // output not reversed
  14. for( int i = 0 ; i < ARRAY_SIZE ; ++i )
  15. {
  16. std::cout << list[i] << '\n';
  17. }
  18.  
  19. std::cout << '\n';
  20.  
  21. // reverse array
  22. for( int i = 0 ; i < ARRAY_SIZE / 2 ; ++i )
  23. {
  24. swapHolder = list[i];
  25. list[i] = list[ARRAY_SIZE - 1 - i];
  26. list[ARRAY_SIZE - 1 - i] = swapHolder;
  27. }
  28.  
  29. // output reversed
  30. for( int i = 0 ; i < ARRAY_SIZE ; ++i )
  31. {
  32. std::cout << list[i] << '\n';
  33. }
  34. }
  35. catch( std::exception &exc )
  36. {
  37. std::cerr << exc.what() << '\n';
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0
1
2
3
4
5
6
7
8
9
10
11

11
10
9
8
7
6
5
4
3
2
1
0