/* Fichier Fonctions.c */ #include void afficher(int age[], char sexe[], int nbPers, char message[]) { int i; printf("Contenu des tableaux %s :\n", message); for(i = 0; i < nbPers; i++) printf("%5d %10d %5c\n", i, age[i], sexe[i]); printf("\n"); } void trier(int age[], char sexe[], int nbPers) { int i, j, indMin, tempo; char tempoCar; /* On fait le tri */ for (i = 0; i < nbPers-1 ; i++) { indMin = i ; for (j = i+1; j < nbPers; j++) if (age[j] < age[indMin]) indMin = j; if(indMin != i) { tempo = age[i]; age[i] = age[indMin]; age[indMin] = tempo; tempoCar = sexe[i]; sexe[i] = sexe[indMin]; sexe[indMin] = tempoCar; } } } int main() { int age[] = { 25, 32, 17, 41, 38 }; char sexe[] = {'M', 'F', 'F', 'M', 'M' }; int nbPers = sizeof(age) / sizeof(int); afficher(age, sexe, nbPers, "avant le tri"); trier(age, sexe, nbPers); afficher(age, sexe, nbPers, "apres le tri"); system("pause"); return 0; } /* Exécution: Contenu des tableaux avant le tri : 0 25 M 1 32 F 2 17 F 3 41 M 4 38 M Contenu des tableaux apres le tri : 0 17 F 1 25 M 2 32 F 3 38 M 4 41 M Appuyez sur une touche pour continuer... */