Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created February 8, 2025 22:29
Show Gist options
  • Select an option

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

Select an option

Save vlaleli/ef1396440169fa4a9a2ffcccf1e2d964 to your computer and use it in GitHub Desktop.
1)
#include <iostream>
using namespace std;
int main() {
int rows, cols, start;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the starting number: ";
cin >> start;
int **arr = new int*[rows];
for (int i = 0; i < rows; i++) {
arr[i] = new int[cols];
}
int value = start;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
arr[i][j] = value;
value *= 2;
}
}
cout << "Array created:\n";
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << arr[i][j] << " \t";
}
cout << endl;
}
for (int i = 0; i < rows; i++) {
delete[] arr[i];
}
delete[] arr;
return 0;
}
2)
#include <iostream>
using namespace std;
int main() {
int rows, cols, start;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the starting number: ";
cin >> start;
int **arr = new int*[rows];
for (int i = 0; i < rows; i++) {
arr[i] = new int[cols];
}
int value = start;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
arr[i][j] = value;
value += 1;
}
}
cout << "Array created:\n";
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << arr[i][j] << " \t";
}
cout << endl;
}
for (int i = 0; i < rows; i++) {
delete[] arr[i];
}
delete[] arr;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment