0

In matrix... How to find the max num in row and the same number is the min in column...?

3 2 1 4 5 6 7 8 9 3 is the min and max

16th Mar 2017, 8:52 PM
‫סער ברודאי‬‎
‫סער ברודאי‬‎ - avatar
1 ответ
+ 1
Running loops: /*...after declaring the matrix and setting up the correspond values of the example you gave...*/ int max=matrix[0][0]; int min=matrix[0][0]; /*we assume that the first element of the matrix is both min and max, initially*/ //two loops to "run" on the matrix in the columns and the rows for(i=0; i<3; i++){ for(j=0; j<3; j++){ if(matrix[ i ][ j ]>max) //if the actual position holds a value bigger than the current max value... max=matrix[ i ][ j ]; //...assume that it is the next max value if(matrix[ i ][ j ]<min) //same as the other if, but for the min value min=matrix[ i ][ j ]; } } /*you can now print the value on the screen using printf and check if it is correct*/ Hope it helped :D
23rd Mar 2017, 3:37 PM
Nox Fortes
Nox Fortes - avatar