1. Number of rows
Description
This is the number of rows of the multidimensional array.
2. Number of columns
Description
This is the number of columns of the multidimensional array.
3. Elements of the multidimensional array
Output
The first line will contain a message prompt to input the number of rows.
The second line will contain a message prompt to input the number of columns.
The succeeding lines will contain the elements of the input multidimensional array.
Finally, the last line will contain the position (row, col) of the first element of the consecutive increasing number.
Enter·number·of·rows:·3
Enter·number·of·columns:·4
1·1·2·3
5·8·2·1
3·2·0·5
Position:·0,·1
#include <iostream>
using namespace std;
int main()
{
int numberOfRows;
int numberOfColumns;
int** array;
cout << "Enter number of rows: ";
cin >> numberOfRows;
cout << "Enter number of columns: ";
cin >> numberOfColumns;
array = new int* [numberOfRows];
for (int i = 0; i < numberOfRows; i++) {
array[i] = new int[numberOfColumns];
}
for (int i = 0; i < numberOfRows; i++) {
for (int j = 0; j < numberOfColumns; j++)
{
cin >> array[i][j];
}
}
for (int i = 0; i < numberOfRows; i++) {
for (int j = 1; j < numberOfColumns; j++)
{
//Comparation the last element of the Row with first element of the next Row
if (i != numberOfRows-1 && j == numberOfColumns-1) {
if (array[i + 1][0] > array[i][j]) {
cout << "Position: " << i << " " << j;
}
break;
}
else if (array[i][j]>array[i][j-1]) {
cout << "Position: " << i << " " << j - 1;
break;
}
}
}
return 0;
}
Comments
Leave a comment