Advertisement
35657

Untitled

Apr 27th, 2024
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void print(int** arr, int row, int col) {
  6.     for (int i = 0; i < row; i++) {
  7.         for (int j = 0; j < col; j++) {
  8.             cout << arr[i][j] << " ";
  9.         }
  10.         cout << endl;
  11.     }
  12.     cout << endl;
  13. }
  14.  
  15. void fill(int** arr, int row, int col) {
  16.     for (int i = 0; i < row; i++) {
  17.         for (int j = 0; j < col; j++) {
  18.             arr[i][j] = rand() % 10;
  19.         }
  20.     }
  21. }
  22.  
  23.  
  24. void rotate_array(int**& arr, int& row, int& col) {
  25.     int** temp = new int* [col];
  26.     for (int i = 0; i < col; i++) {
  27.         temp[i] = new int[row];
  28.         for (int j = 0; j < row; j++) {
  29.             temp[i][j] = arr[row - j - 1][i];
  30.         }
  31.     }
  32.     for (int i = 0; i < row; i++) {
  33.         delete[] arr[i];
  34.     }
  35.     delete[] arr;
  36.     arr = temp;
  37.     int buf = row;
  38.     row = col;
  39.     col = buf;
  40. }
  41.  
  42. int main() {
  43.     setlocale(LC_ALL, "ru");
  44.  
  45.     srand(time(NULL));
  46.  
  47.     int row = 6, col = 8;
  48.  
  49.     int** arr = new int* [row];
  50.  
  51.     for (int i = 0; i < row; i++) {
  52.         arr[i] = new int[col];
  53.     }
  54.  
  55.     fill(arr, row, col);
  56.  
  57.     print(arr, row, col);
  58.  
  59.     rotate_array(arr, row, col);
  60.  
  61.     print(arr, row, col);
  62.  
  63.     for (int i = 0; i < row; i++) {
  64.         delete[] arr[i];
  65.     }
  66.     delete[] arr;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement