Advertisement
35657

Untitled

Apr 27th, 2024
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 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. void change_column(int** arr, int row, int index1, int index2) {
  24.     for (int i = 0; i < row; i++) {
  25.         int temp = arr[i][index1];
  26.         arr[i][index1] = arr[i][index2];
  27.         arr[i][index2] = temp;
  28.     }
  29. }
  30.  
  31. int main() {
  32.     setlocale(LC_ALL, "ru");
  33.  
  34.     srand(time(NULL));
  35.  
  36.     int row = 5, col = 5;
  37.  
  38.     int** arr = new int* [row];
  39.  
  40.     for (int i = 0; i < row; i++) {
  41.         arr[i] = new int[col];
  42.     }
  43.  
  44.     fill(arr, row, col);
  45.  
  46.     print(arr, row, col);
  47.  
  48.     change_column(arr, row, 0, 1);
  49.  
  50.     print(arr, row, col);
  51.  
  52.     for (int i = 0; i < row; i++) {
  53.         delete[] arr[i];
  54.     }
  55.     delete[] arr;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement