Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // Fonction tableaux avant tri
- void afficher (char poste[], int nbCafe[], int age[], int nbEmp)
- {
- int i;
- printf("contenu des trois tableaux avant le tri :\n");
- printf("indice poste nbCafe age\n");
- for(i = 0; i < nbEmp; i+=1)
- printf ("%3i %4c %4i %3i\n", i, poste[i], nbCafe[i], age[i]);
- printf("\n\n");
- }
- // Fonction compteur
- int nombre(char posteVoulu, char poste[], int nbEmp)
- {
- int n = 0, i;
- for(i = 0; i < nbEmp; i+=1)
- if(poste[i] == posteVoulu)
- n++;
- return n;
- }
- // Fonction moyenne
- float moyenne(int tableau[], int nbEmp)
- {
- float somme = 0;
- int i;
- for(i = 0; i < nbEmp; i+=1)
- somme += tableau[i];
- return somme / nbEmp;
- }
- // Fonction tri des tableaux
- void trier(char poste[], int nbCafe[], int age[], int nbEmp)
- {
- int i;
- for (i = 0; i < nbEmp-1; i++)
- {
- int indMin = i, j;
- for (j = i+1; j < nbPers; j++)
- if (age[j] < age[indMin])
- indMin = j;
- if(indMin != i)
- {
- int tempo1 = age[i];
- age[i] = age[indMin];
- age[indMin] = tempo1;
- tempo1 = nbCafe[i];
- nbCafe[i] = nbCafe[indMin];
- nbCafe[indMin]= tempo1;
- char tempoCar = poste[i];
- poste[i] = poste[indMin];
- poste[indMin] = tempoCar;
- }
- }
- }
- // Fonction principale
- int main()
- {
- char poste [] = {'P', 'P', 'O', 'A', 'P', 'A', 'P', 'P'};
- int nbCafe [] = {3, 1, 6, 0, 5, 1, 0, 3},
- age [] = {25, 19, 27, 26, 49, 24, 56, 29},
- nbEmp = sizeof(age)/sizeof(int);
- // Tableux avant tri
- afficher (poste, nbCafe, age, nbEmp);
- // Afficher compteurs
- printf("Le nombre de programmeurs : %d\n", nombre('P', statut, nbPers));
- printf("Le nombre de secretaires : %d\n", nombre('S', statut, nbPers));
- printf("Le nombre d analystes : %d\n\n", nombre('A', statut, nbPers));
- // Afficher moyennes
- printf("L age moyen : %.2f ans\n", moyenne (age, nbEmp));
- printf("La consommation moyenne de cafe : %.2f cafe(s)\n\n", moyenne (cafe, nbEmp));
- // Trier tableaux
- trier(poste, nbCafe, age, nbEmp);
- // Afficher tableaux apres tri
- afficher(poste, nbCafe, age, nbEmp, "apres le tri selon les ages\n");
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement