The requirements for this example are:
* In a two-dimensional integer array of n rows n columns, *
Select two numbers according to the following requirements.
* First select the maximum number from each line, and select the minimum number from the selected n maximum number;
* Second, select the minimum number from each line, and then select the maximum number from the selected n decimal places. *
Here's my Code, and in the comments I can see my idea:
#include <stdio.h>/** * Instance requirements: * In a two-dimensional integer array of n rows n columns, * Two numbers are selected according to the following requirements. * First select the maximum number from each row, select the minimum number from the selected n maximum number, and second, select the minimum number from each row, and then select the maximum number from the selected n decimal places. * */intMainvoid){intOrder 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);intMatrix[order][order];/** * Get user input and populate in a two-dimensional array */ intColums,rows; for(rows =0; rows < order;rows++) { for(colums =0; Colums < order;colums++) {scanf ("%d", &matrix[rows][colums]);//This can also be written here //scanf ("%d", matrix[rows]+colums);} }/** * Find the smallest element of the largest element * */ //To hold the smallest element in the largest element intMininmax =0; for(rows =0; rows < order;rows++) {//To save the maximum line element intMaxinline =0; for(colums =0; colums < order;colums++) {if(Matrix[rows][colums] > Maxinline) maxinline = Matrix[rows][colums]; }if(Rows = =0){//When getting the largest element of the first row, assign the value to the smallest element directlyMininmax = Maxinline; }Else{if(Mininmax > Maxinline) mininmax = Maxinline; }} printf ("The minimum of maximum number is%d.\n", Mininmax);/** * Find the largest element of the smallest element * */ //To hold the largest element in the smallest element intMaxinmin =0; for(rows =0; rows < order;rows++) {//To save the minimum line element intMininline = matrix[rows][0]; for(colums =0; colums < order;colums++) {if(Matrix[rows][colums] < mininline) Mininline = Matrix[rows][colums]; }if(Rows = =0){//When obtaining the smallest element of the first row, assign the value directly to the largest elementMaxinmin = Mininline; }Else{if(Maxinmin < Mininline) maxinmin = Mininline; }} printf ("The maximum of minimum number is%d.\n", maxinmin);return 0;}
C Two-dimensional array exercises