avr39ripe

cppArrReverse

Mar 24th, 2021
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int arrSize{ 10 };
  6.     int arr[arrSize]{1,2,3,4,5,6,7,8,9,10};
  7.     int tmp{ 0 };
  8.  
  9.     for (int head{ 0 }, tail{ arrSize - 1 }; head<tail; ++head, --tail)
  10.     {
  11.         tmp = arr[head];
  12.         arr[head] = arr[tail];
  13.         arr[tail] = tmp;
  14.     }
  15.     std::cout << '\n';
  16.  
  17.     for (int i{ 0 }; i < arrSize; ++i)
  18.     {
  19.         std::cout << arr[i] << ' ';
  20.     }
  21.     std::cout << '\n';
  22.        
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment