35657

Untitled

Nov 25th, 2023
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <time.h> // для подключения функции time()
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. int main() {
  10.  
  11.     setlocale(LC_ALL, "ru");
  12.    
  13.     int arr1[3][4]; //создаем пустой массив 3х4(3 строки, 4 столбца)
  14.    
  15.     // каждую строку заключаем в отдельные скобки
  16.     int arr2[2][2] = { {1,2}, {7,8} };
  17.  
  18.     // значения указываем подряд
  19.     int arr3[2][2] = { 1, 2, 7, 8 };
  20.  
  21.     // недостающие значения будут дополнены нулями
  22.     int arr4[3][3] = { {1,2}, {7,8,9} };
  23.  
  24.     // инициализация с помощью цикла
  25.  
  26.     const int row = 3;
  27.  
  28.     const int col = 5;
  29.  
  30.     int arr[row][col]; // равносильно int arr[3][5]
  31.  
  32.     srand(time(NULL));
  33.  
  34.     for (int i = 0; i < row; i++) {
  35.         for (int j = 0; j < col; j++) {
  36.             arr[i][j] = rand() % 100;
  37.         }
  38.     }
  39.  
  40.     for (int i = 0; i < row; i++) {
  41.         for (int j = 0; j < col; j++) {
  42.             cout << arr[i][j] << "\t";
  43.         }
  44.         cout << endl;
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment