35657

Untitled

Jan 25th, 2024
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Fill(int** arr, int lines, int cols) {
  6.     for (int i = 0; i < lines; i++) {
  7.         for (int j = 0; j < cols; j++) {
  8.             arr[i][j] = rand() % 100;
  9.         }
  10.     }
  11. }
  12.  
  13. void Print(int** arr, int lines, int cols) {
  14.     for (int i = 0; i < lines; i++) {
  15.         for (int j = 0; j < cols; j++) {
  16.             cout << arr[i][j] << '\t';
  17.         }
  18.         cout << endl;
  19.     }
  20.     cout << endl;
  21. }
  22.  
  23. int main() {
  24.  
  25.     srand(time(NULL));
  26.  
  27.     int lines = 5, cols = 5;
  28.  
  29.     int** arr = new int* [lines];
  30.    
  31.     for (int i = 0; i < lines; i++) {
  32.         arr[i] = new int[cols];
  33.     }
  34.  
  35.     Fill(arr, lines, cols);
  36.  
  37.     Print(arr, lines, cols);
  38.  
  39.     for (int i = 0; i < lines; i++) {
  40.         delete[] arr[i];
  41.     }
  42.     delete[] arr;
  43.  
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment