# 找到列中的最大元素，同时也是矩阵中行中的最小元素

[英]finding the max element in the columns while also being the min in the lines in a matrix

``````
int L , C , i , j ,maxc,minl ;
int Tab[20][20];
printf("Introduire le nombre des lignes du matrice (MAX 20): ");
scanf("%d",&L);
printf("Introduire le nombre des colonnes du matrice (MAX 20): ");
scanf("%d",&C);
for(i=0; i<L; i++)
{
for(j=0; j<C; j++)
{
printf("Donner l'element (%d,%d): ",i+1,j+1);
scanf("%d", &Tab[i][j]);
}
}

for(j=0 ;j<C;j++)
{
maxc=Tab[0][j];
for(i=0;i<L;i++)
{
minl=Tab[i][0];
if(Tab[i][j]>maxc && Tab[i][j]<minl )
{
printf("Tab[%d,%d]=%d ",i+1,j+1,Tab[i][j]);
}
else
{
printf("La matrice ne contient aucun Min-Max.");
}
}
}

return 0;
}
``````

``````int Tab[L][C];
``````

``````int L, C, min, max;

printf("Introduire le nombre des lignes du matrice:\n");
scanf("%d", &L);
printf("Introduire le nombre des colonnes du matrice:\n");
scanf("%d", &C);

int Tab[L][C]; //Declare it here with the right size
int i; //Index for iterating over rows
int j; //Index for iterating over columns
int a; //Index of the column with the minimum value (for each row)
int k; //Index for iterating the column that contains the min row value.
bool found = false;

for(i=0; i<L; i++){
for(j=0; j<C; j++){
printf("Donner l'element (%d, %d): ", i, j);
scanf("%d", &Tab[i][j]);

if(j==0){
min = max = Tab[i][j];
} else {
//Store the minimum and max values while user input them
if(Tab[i][j]<min) min = Tab[i][j];
if(Tab[i][j]>max) max = Tab[i][j];
}
}
}

for(i=0; i<L; i++){
//You need to reset 'maxc' and 'minl' for every row, otherwise you will compare it with the minimum and maximum values of the previous rows
int maxc = min-1;
int minl = max+1;
for(j=0; j<C; j++){
if(Tab[i][j]<minl){
minl = Tab[i][j];
a = j;
}
if(j==C-1){ //Here 'a' contains the row index of the minimum element of the row 'i'
for(k=0; k<L; k++){ //Iterating the column with 'a' index: we search for the maximum value in that column
if(Tab[k][a]>maxc) maxc = Tab[k][a];
if(k==L-1){ // Here 'a' contains the row index of the minimum element of the row 'i' (minl variable), and also here the maxc variable contains the maximum element of the row 'i'.
if(minl == maxc){
printf("Tab[%d,%d]=%d ", i, a, Tab[i][a]);
found = true;
}
}
}
}
}
}
if(!found) printf("La matrice ne contient aucun Min-Max.");
``````

© 2020-2023 STACKOOM.COM