If I understand your question correctly, you want the row number of the entered value and not the matrix. For both forms, you can monitor the inserts (variable insercoes
) and save the value of the minor insert into a variable (in this case linhaDoMenorNumero
) or update the variable with the current row index of its matrix (variable i
):
int m[4][4], i, j, menor, linhaDoMenorNumero, insercoes = 0;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
cin >> m[i][j];
insercoes++;
if (i == 0 and j == 0) {
menor = m[0][0];
}
if(m[i][j] < menor) {
// para encontrar a linha da matriz, basta substituir "insercoes" por "i"
linhaDoMenorNumero = insercoes;
menor = m[i][j];
}
}
}
cout << "O menor numero e: " << menor << endl;
cout << "Na linha: " << linhaDoMenorNumero << endl;
return 0;
I hope I’ve helped in some way.
thank you so much!
– Victoria Moraes