Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created February 12, 2025 13:40
Show Gist options
  • Select an option

  • Save vlaleli/5b5bfc568bdbaf225756299329b255cf to your computer and use it in GitHub Desktop.

Select an option

Save vlaleli/5b5bfc568bdbaf225756299329b255cf to your computer and use it in GitHub Desktop.
1)
#include <iostream>
using namespace std;
int main() {
const int ROWS = 3;
const int COLS = 3;
int arr[ROWS][COLS];
int num;
cout << "Enter number:";
cin >> num;
arr[0][0] = num;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
if (i == 0 && j == 0) continue;
if (j == 0)
arr[i][j] = arr[i - 1][COLS - 1] * 2;
else
arr[i][j] = arr[i][j - 1] * 2;
}
}
cout << "Created array:" << endl;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
2)
#include <iostream>
using namespace std;
int main() {
const int ROWS = 3;
const int COLS = 3;
int arr[ROWS][COLS];
int num;
cout << "Enter number: ";
cin >> num;
arr[0][0] = num;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
if (i == 0 && j == 0) continue;
if (j == 0)
arr[i][j] = arr[i - 1][COLS - 1] + 1;
else
arr[i][j] = arr[i][j - 1] + 1;
}
}
cout << "Created array:" << endl;
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment