1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct fiche
{
int joueur;
};
/* affichage du tableau */
static void aff (struct fiche const *a, size_t n)
{
size_t i;
for (i = 0; i < n; i++)
{
/* pointeur intermediaire pour alleger l'ecriture */
struct fiche const *p = a + i;
printf ("%-10s %-10s \n", p->joueur);
}
printf ("\n");
}
/* fonction utilisateur de comparaison fournie a qsort() */
static int compare_joueur_dec (void const *a, void const *b)
{
struct fiche const *pa = a;
struct fiche const *pb = b;
return pb->joueur - pa->joueur;
}
int main()
{
int chance = 0, logique = 0, mental = 0;
int joueur[4];
int i;
for(i = 1 ; i < 4 ; i++)
{
printf("\n\n Joueur %d, entrez Chance, Logique et Niveau\n",i);
scanf("%d", &chance);
scanf("%d", &logique);
scanf("%d", &niveau);
joueur[i] = (chance * 2) + logique + niveau;
}
/* tableau a trier (tableau de pointeurs sur char const) */
struct fiche tab[] = { "joueur", joueur };
qsort (tab, sizeof tab / sizeof *tab, sizeof *tab, compare_joueur_dec);
/* affichage du tableau apres le tri */
aff (tab, sizeof tab / sizeof *tab);
return 0;
} |
Partager