It is necessary to find the maximum element of each row in the array, display it on the screen, and also output the row and column number.

int a, b; for (i = 1; i <= n; i++) { int max = 0; for (j = 1; j <= m; j++) { if (mas[i][j] > max) max = mas[i][j]; a = i; b = j; } cout <<"максимальный элемент="<< max << "\n "; cout <<"номер строки="<<a<< "\n "; cout <<"номер столбца="<< b<< "\n"; } 

column number is not displayed correctly

    1 answer 1

    At a minimum, you have an incorrect numbering - in C / C ++ the elements of the matrix are numbered from zero.

    Secondly, in my opinion, you misplaced the brackets ...

    In general, look, understand ...

     int main() { const int n = 5; int mas[n][n]; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { mas[i][j] = rand()%20 - 10; cout << setw(6) << mas[i][j]; } cout << endl; } cout << "\n"; for(int i = 0; i < n; i++) { int max = mas[i][0]; int idx = 0; for(int j = 1; j < n; j++) { if (mas[i][j] > max) { max = mas[i][j]; idx = j; } } cout << "В строке " << i << " максимальный элемент " << max << " находится в столбце" << idx <<"\n"; } }