Advertisement
Infiniti_Inter

Массивчики

Dec 16th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int n;
  7.  
  8. void swap_cow(int** a)
  9. {
  10.     int rg, lf;
  11.     if (n % 2 == 0)
  12.     {
  13.         rg = n / 2;
  14.         lf = rg - 1;
  15.     }
  16.     else
  17.     {
  18.         rg = n / 2;
  19.         lf = 0;
  20.     }
  21.     for (int i = 0; i < n; ++i)
  22.     {
  23.         int buff = a[i][rg];
  24.         a[i][rg] = a[i][lf];
  25.         a[i][lf] = buff;
  26.     }
  27.  
  28. }
  29. int main()
  30. {
  31.     cin >> n;
  32.     int** a = new int* [n];
  33.     for (int i = 0; i < n; ++i)
  34.         a[i] = new int[n];
  35.     for (int i = 0; i < n; ++i)
  36.         for (int j = 0; j < n; ++j)
  37.             cin >> a[i][j];
  38.     swap_cow(a);
  39.  
  40.     for (int i = 0; i < n; ++i)
  41.     {
  42.         for (int j = 0; j < n; ++j)
  43.             cout << a[i][j] << '\t';
  44.         cout << endl;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement