Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void print(int** arr, int row, int col) {
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- }
- void fill(int** arr, int row, int col) {
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- arr[i][j] = rand() % 10;
- }
- }
- }
- void rotate_array(int**& arr, int& row, int& col) {
- int** temp = new int* [col];
- for (int i = 0; i < col; i++) {
- temp[i] = new int[row];
- for (int j = 0; j < row; j++) {
- temp[i][j] = arr[row - j - 1][i];
- }
- }
- for (int i = 0; i < row; i++) {
- delete[] arr[i];
- }
- delete[] arr;
- arr = temp;
- int buf = row;
- row = col;
- col = buf;
- }
- int main() {
- setlocale(LC_ALL, "ru");
- srand(time(NULL));
- int row = 6, col = 8;
- int** arr = new int* [row];
- for (int i = 0; i < row; i++) {
- arr[i] = new int[col];
- }
- fill(arr, row, col);
- print(arr, row, col);
- rotate_array(arr, row, col);
- print(arr, row, col);
- for (int i = 0; i < row; i++) {
- delete[] arr[i];
- }
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement