MargaritaOwl

swap for chetverty

May 14th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include<iomanip>
  3. #include<ctime>
  4. using namespace std;
  5. void main()
  6. {
  7.     srand(time(NULL));
  8.     const int n = 5;
  9.     int mas[n][n];
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         for (int j = 0; j < n; j++)
  13.             mas[i][j] = rand() % 9 +1;
  14.     }
  15.     cout << "Source array:" << endl;
  16.     for (int i = 0; i < n; i++)
  17.     {
  18.         for (int j = 0; j < n; j++)
  19.             cout << setw(4) << mas[i][j];
  20.         cout << endl;
  21.     }
  22.     for (int i = 0; i<n/2; i++)
  23.         for (int j = 0; j < n/2; j++)
  24.         {
  25.             if(n==n%2)swap(mas[i][j],mas[n / 2 + i][n / 2 + j]);
  26.             else {
  27.                 swap(mas[i][j], mas[n - 1 - i][n - 1 - j]);
  28.                 //int tmp = mas[i][i];mas[i][i] = mas[n - 1 - i][n - 1 - i];mas[n - 1 - i][n - 1 - i] = tmp;
  29.             }
  30.         }
  31.     cout << "Result array:" << endl;
  32.     for (int i = 0; i < n; i++)
  33.     {
  34.         for (int j = 0; j < n; j++)
  35.             cout << setw(4) << mas[i][j];
  36.         cout << endl;
  37.     }
  38.     system("pause");
  39. }
Add Comment
Please, Sign In to add comment