In your last attempt, you did not correct the indices (starting at 0).
Moreover, the real test for monotony is between j - 1
and j
elements. Here is the corrected code :
#include <iostream>
using namespace std;
int main ()
{
int n;
cout << "Kvadrat Matriciin irembiig oruulnuu:" << endl;
cin >> n;
int M [n] [n] ;
for ( int i = 0 ; i < n; i++) {
for ( int j = 0 ; j < n; j++) {
cout << "[" << i << "]" << "[" << j << "]" << " Bairshiltai Toog oruulnuu" << endl ;
cin >> M [i] [j] ;
}
}
for ( int i = 0 ; i < n ; i++) {
bool monotonic = true;
for ( int j = 1 ; j < n; j++) {
monotonic = monotonic && (M [i] [j-1] < M [i] [j]);
}
cout << "[" << i << "] : " << "monotonic = " << monotonic << "\n" ;
}
}
1
solved Optimising code to find which row in an array has a monotone increment