niyaznigmatullin

reverse array

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