Skip to content

Instantly share code, notes, and snippets.

@rohachevsk
Created February 8, 2025 17:07
Show Gist options
  • Save rohachevsk/3e7e69b9826516326256791649f6d944 to your computer and use it in GitHub Desktop.
Save rohachevsk/3e7e69b9826516326256791649f6d944 to your computer and use it in GitHub Desktop.
Напишіть програму, яка створює двовимірний масив і заповнює його за таким принципом: користувач вводить число (наприклад, 3) перший елемент масиву приймає значення цього числа, наступний елемент масиву приймає значення цього числа + 1
#include <iostream>
using namespace std;
int main()
{
const int rows = 3;
const int cols = 3;
int n;
cout << "enter n ... ";
cin >> n;
int arr[rows][cols];
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
arr[i][j] = n;
n +=1;
}
}
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
cout << arr[i][j] << ' ';
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment