Advertisement
Zennoma

laba12b

Feb 20th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int n, m;
  9.     puts("inputed row number");
  10.     cin >> n;
  11.     int** array = new int* [n]; // Создаем массив указателей
  12.     puts("input collums number");
  13.     cin >> m;
  14.     puts("generated matrix");
  15.    
  16.     for (int i = 0; i < n; i++)
  17.     {
  18.         array[i] = new int[m]; // Создаем элементы
  19.     }
  20.     for (int i = 0; i < n; i++)
  21.     {
  22.         for (int j = 0; j < m; j++)
  23.         {
  24.             cout.width(10);
  25.             *(*(array + i) + j) = rand() % 21 - 10;
  26.             cout  << *(*(array + i) + j);
  27.         }
  28.         cout << endl;
  29.     }
  30.     cout << "shifted matrix"<<endl;
  31.    
  32.     int j =0;
  33.     int i = 0;
  34.     int difference=0;
  35.     int max;
  36.     if (n < m)
  37.         max = m;
  38.     else max = n;
  39.     for (int p = 0; p < 2*max-1; p++)
  40.     {
  41.  
  42.         while ( i>=difference )
  43.         {
  44.             if (i >= n )
  45.             {
  46.                 difference = n-i-1;
  47.                 while (difference != 0)
  48.                 {
  49.                     cout.width(10);
  50.                     cout << "";
  51.                     i--;
  52.                     difference++;
  53.                     j++;
  54.                 }
  55.             }
  56.             cout.width(10);
  57.             if (j<m)
  58.             cout << *(*(array + i) + j);
  59.             i--;
  60.             j++;
  61.            
  62.         }
  63.         j = 0;
  64.         i = p + 1;
  65.         cout << endl;
  66.     }
  67.        
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement