Home > Back-end >  O great god answer
O great god answer

Time:09-22

Has a 3 x 4 a two-dimensional array of [3] [4]={{1, 2, 3, 4}, {9,8,7,6}, {- 10, 10, 5, 2}}, for programming the value of one of the biggest value of the elements, as well as its place of line and column number,

CodePudding user response:

To a double loop

CodePudding user response:

 
Int a [3] [4]={{1, 2, 3, 4}, {9,8,7,6}, {- 10, 10, 5, 2}}, idx_i, idx_j;

Int I, j, Max.

Max=a [0] [0];
Idx_i=idx_j=0;
for (i=0; i <3; I++)
For (j=0; J & lt; 4. J++)
If (a [I] [j] & gt; Max) {
Max=a, [I] [j].
Idx_i=I;
Idx_j=j;
}

Printf (" a [% d] [% d]=% d \ n ", idx_i, idx_j, Max).


For your reference ~

CodePudding user response:

# include & lt; String>
# include & lt; Iostream>


using namespace std;


Int main (int arg c, char * * argv)
{
Int m=0, row=0, col=0;
Int a [3] [4]={{1, 2, 3, 4}, {9,8,7,6}, {- 10, 10, 5, 2}};
M=a [0] [0];
for(int i=0; i<3; I++)
{
For (int j=0; j<4. J++)
{
If (m & lt; A [I] [j])
{
M=a, [I] [j].
The row=I;
Col=j;
}
}
}
Printf (" Max is % d, the row is % d, col is % d \ n ", m, the row, col);
return 0;
}
  • Related