/* Fichier Tri.c Exemple de tableaux et du tri par sélection Voir Fonctions.c pour la version utilisant de fonctions */ #include int main() { int age[] = { 25, 32, 17, 41, 38 }; char sexe[] = {'M', 'F', 'F', 'M', 'M' }; int nbPers = sizeof(age) / sizeof(int); int i, j, indMin, tempo; char tempoCar; /* afficher les tableaux avant le tri : */ printf("Contenu des tableaux avant le tri :\n"); for(i = 0; i < nbPers; i++) printf("%5d %10d %5c\n", i, age[i], sexe[i]); printf("\n"); /* 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; } } /* afficher les tableaux après le tri : */ printf("Contenu du tableau apres le tri :\n"); for(i = 0; i < nbPers; i++) printf("%5d %10d%5c\n", i, age[i], sexe[i]); printf("\n"); 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 du tableau apres le tri : 0 17 F 1 25 M 2 32 F 3 38 M 4 41 M Appuyez sur une touche pour continuer... */