Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h> // для подключения функции time()
- using namespace std;
- int main() {
- setlocale(LC_ALL, "ru");
- int arr1[3][4]; //создаем пустой массив 3х4(3 строки, 4 столбца)
- // каждую строку заключаем в отдельные скобки
- int arr2[2][2] = { {1,2}, {7,8} };
- // значения указываем подряд
- int arr3[2][2] = { 1, 2, 7, 8 };
- // недостающие значения будут дополнены нулями
- int arr4[3][3] = { {1,2}, {7,8,9} };
- // инициализация с помощью цикла
- const int row = 3;
- const int col = 5;
- int arr[row][col]; // равносильно int arr[3][5]
- srand(time(NULL));
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- arr[i][j] = rand() % 100;
- }
- }
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- cout << arr[i][j] << "\t";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment