Created
February 8, 2025 22:29
-
-
Save vlaleli/ef1396440169fa4a9a2ffcccf1e2d964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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