Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include<iostream>
  2. #include<ctime>
  3.  
  4. using namespace std;
  5.  
  6. void create_B(int A[10][10], int B[10][10], int n)
  7. {
  8.     int k = 0, l = 0;
  9.     for(int i = n - 1; i >= 0; i--)
  10.     {
  11.         for(int j = 0; j < n; j++)
  12.         {
  13.             B[k][l] = A[i][j];
  14.             //printf("i = %d, j = %d, k = %d, l = %d\n", i,j,k,l);
  15.             l++;
  16.         }
  17.         k++;
  18.         l = 0;
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     srand(time(NULL));
  25.     int n, A[10][10], B[10][10];
  26.     cin >> n;
  27.     for(int i = 0; i < n; i++)
  28.     {
  29.         for(int j = 0; j < n; j++)
  30.         {
  31.             A[i][j] = (rand() % 18) - 9;
  32.         }
  33.     }
  34.     create_B(A, B, n);
  35.     for(int i = 0; i < n; i++)
  36.     {
  37.         for(int j = 0; j < n; j++)
  38.         {
  39.             if(i == n/2 && j == 0)
  40.             {
  41.                 cout << "A = ";
  42.             }
  43.             else if(j == 0)
  44.             {
  45.                 cout << "    ";
  46.             }
  47.             cout << A[i][j] << " ";
  48.         }
  49.         cout << endl;
  50.     }
  51.     cout << endl;
  52.     for(int i = 0; i < n; i++)
  53.     {
  54.         for(int j = 0; j < n; j++)
  55.         {
  56.             if(i == n/2 && j == 0)
  57.             {
  58.                 cout << "B = ";
  59.             }
  60.             else if(j == 0)
  61.             {
  62.                 cout << "    ";
  63.             }
  64.             cout << B[i][j] << " ";
  65.         }
  66.         cout << endl;
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement