C Two-dimensional array exercises
The requirements for this instance are:
* In the two-dimensional integer array of n rows and n columns ,*
Select two numbers according to the following requirements.
* First, select the maximum number from each row, and then select the minimum number from the n largest numbers ;*
* Select the minimum number from each row, and then select the maximum number from the n decimal places. *
The following is my code. I can see my thoughts in the comments:
# Include
/*** Instance requirement: * in the two-dimensional integer array of n rows and n columns, * two numbers are selected according to the following requirements. * First, select the maximum number from each row, and then select the minimum number from the n largest numbers. * Second, select the minimum number from each row, then, select the maximum number from the n decimal places. **/Int main (void) {int order; printf ("% s \ n", "Please enter the order of the matrix:"); scanf ("% d ", & order); printf ("Please input the elements of the matrix, from a [0] [0] to a [% d] [% d]: \ n ", order-1, order-1); int matrix [order] [order];/*** get user input and fill it in a two-dimensional array */int colums, rows; for (rows = 0; rows <order; rows ++) {for (colums = 0; colums <order; colums ++) {scanf ("% d ", & matrix [rows] [colums]); // You can also write it here // scanf ("% d", matrix [rows] + colums );}} /*** find the minimum element of the maximum element ** // It is used to save the minimum element int minInMax = 0; for (rows = 0; rows <order; rows ++) {// used to save the maximum Row Element int maxInLine = 0; for (colums = 0; colums <order; colums ++) {if (matrix [rows] [colums]> maxInLine) maxInLine = matrix [rows] [colums];} if (rows = 0) {// when the maximum element of the first line is obtained, the minimum element minInMax = maxInLine is assigned directly;} else {if (minInMax> maxInLine) minInMax = maxInLine ;}} printf ("The minimum of maximum number is % d. \ n ", minInMax);/*** find the maximum element of the smallest element ** // It is used to save the maximum element int maxInMin = 0; for (rows = 0; rows <order; rows ++) {// used to save the minimum element int minInLine = matrix [rows] [0]; for (colums = 0; colums <order; colums ++) {if (matrix [rows] [colums] <minInLine) minInLine = matrix [rows] [colums];} if (rows = 0) {// when the minimum element of the first line is obtained, the maximum element maxInMin = minInLine is assigned directly;} else {if (maxInMin <minInLine) maxInMin = minInLine ;}} printf ("The maximum of minimum number is % d. \ n ", maxInMin); return 0 ;}