// Tu as ta matrice[ylength][xlength] int x, y, xmem=-1, ymem=-1, xmax, mindesmax=0x7FFFFFFF; for( y=0; y<ylength; y++) { xmax=-0x7FFFFFFE; for( x=0; x<xlength; x++) { if( matrice[y][x]>xmax) { xmax= matrice[y][x]; } } if( xmax<mindesmax) // '<' pour avoir le premier, '<=' pour avoir le dernier { mindesmax= xmax; xmem= x; ymem= y; } } // Ici tu as ton résultat mindesmax en position [ymem][xmem] dans ta matrice // Dans le cas particulier ou absolument toutes les valeurs sont égales à -0x7FFFFFFE alors tu auras mindesmax=-0x7FFFFFFE et // - si tu as choisi de sortir le premier tu auras xmem=-1 et ymem=-1 // - si tu as choisi de sortir le dernier tu auras xmem=xlength-1 et ymem=ylength-1
#include <stdio.h> #define NBCOLMAX 0xFF void MinDesMax( int xlength, int ylength, int matrice[][NBCOLMAX], int *mindesmax, int *xmem, int *ymem) { int x, y, xmax; *mindesmax=0x7FFFFFFF; *xmem=0; *ymem=0; for( y=0; y<ylength; y++) { xmax=0; for( x=1; x<xlength; x++) { if( matrice[y][x]>matrice[y][xmax]) // '>' pour avoir le premier, '>=' pour avoir le dernier { xmax= x; } } if( matrice[y][xmax]<*mindesmax) // '<' pour avoir le premier, '<=' pour avoir le dernier { *mindesmax= matrice[y][xmax]; *xmem= xmax; *ymem= y; } } } int main() { // Exemple, mais tu fais ça dynamiquement int xlength=4, ylength=5; int matrice[][NBCOLMAX]= { { 21, 46, 94, 47 }, { 45, 83, 64, 15 }, { 14, 57, 42, 51 }, { 98, 15, 36, 74 }, { 17, 29, 98, 66 } }; int xmem, ymem, mindesmax; MinDesMax( xlength, ylength, matrice, &mindesmax, &xmem, &ymem); printf("%i en [%i][%i]", mindesmax, ymem, xmem); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question