Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<time.h>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int n, m;
- puts("inputed row number");
- cin >> n;
- int** array = new int* [n]; // Создаем массив указателей
- puts("input collums number");
- cin >> m;
- puts("generated matrix");
- for (int i = 0; i < n; i++)
- {
- array[i] = new int[m]; // Создаем элементы
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout.width(10);
- *(*(array + i) + j) = rand() % 21 - 10;
- cout << *(*(array + i) + j);
- }
- cout << endl;
- }
- cout << "shifted matrix"<<endl;
- int j =0;
- int i = 0;
- int difference=0;
- int max;
- if (n < m)
- max = m;
- else max = n;
- for (int p = 0; p < 2*max-1; p++)
- {
- while ( i>=difference )
- {
- if (i >= n )
- {
- difference = n-i-1;
- while (difference != 0)
- {
- cout.width(10);
- cout << "";
- i--;
- difference++;
- j++;
- }
- }
- cout.width(10);
- if (j<m)
- cout << *(*(array + i) + j);
- i--;
- j++;
- }
- j = 0;
- i = p + 1;
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement