Last active
November 8, 2017 18:59
-
-
Save kindlyfire/9e6e6742efe027a9c7668e2a50192121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
float premier = 0; | |
float deuxieme = 0; | |
float troisieme = 0; | |
float quatrieme = 0; | |
printf("Entrez le score du premier candidat\n"); | |
scanf("%f", &premier); | |
printf("Entrez le score du deuxieme candidat\n"); | |
scanf("%f", &deuxieme); | |
printf("Entrez le score du troisieme candidat\n"); | |
scanf("%f", &troisieme); | |
printf("Entrez le score du quatrieme candidat\n"); | |
scanf("%f", &quatrieme); | |
if (premier >= 50){ | |
printf("Le premier candidat est elu\n"); | |
} else if(deuxieme >= 50 || troisieme >= 50 || quatrieme >= 50){ | |
printf("Le premier candidat est battu"); | |
} else { | |
if (premier < 12.5){ | |
printf("Le premier candidat est disqualifie"); | |
} else if (premier > 12.5){ | |
if (premier > deuxieme || premier > troisieme || premier > quatrieme) { | |
printf("Le premier candidat se trouve en ballotage favorable"); | |
} else { | |
printf("Le premier candidat se trouve en ballotage defavorable"); | |
} | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define N_PARTICIPANTS 4 | |
/* | |
* Ce programme traite une liste de participants à une élection législative | |
* et calcule si chaque participant est élu, battu, se trouve en ballotage | |
* favorable ou défavorable. | |
*/ | |
int main() | |
{ | |
float participants[N_PARTICIPANTS]; | |
int i, j, score, elu = -1, plus_haut_score; | |
/* | |
* On récupère le suffrage de | |
*/ | |
for (i = 0; i < N_PARTICIPANTS; ++i) | |
{ | |
printf("Score du participant %i: ", i + 1); | |
scanf("%f", &participants[i]); | |
if (participants[i] > plus_haut_score || i == 0) { | |
plus_haut_score = participants[i]; | |
} | |
} | |
printf("\n"); | |
/* | |
* On fait un tour dans les participants et on regarde si il y en a un qui | |
* a plus de 50% des suffrages. | |
*/ | |
for (i = 0; i < N_PARTICIPANTS; ++i) | |
{ | |
score = participants[i]; | |
if(score >= 50.0) { | |
elu = i; | |
} | |
} | |
/* | |
* Si il y a un élu, on re-traverse la boucle pour afficher les élus/battus | |
* à l'écran. | |
*/ | |
if (elu != -1) { | |
for (i = 0; i < N_PARTICIPANTS; ++i) | |
{ | |
printf("Participant %i: ", i + 1); | |
if(elu == i) { | |
printf("élu\n"); | |
} | |
else { | |
printf("battu\n"); | |
} | |
} | |
// Retour prémature car il n'y a plus rien à faire | |
return 0; | |
} | |
/* | |
* Si il n'y a pas d'élu, on regarde si il y a des candidats avec un suffrage | |
* est en dessous de 12,5%, ils sont éliminés. | |
* | |
* Si le candidat a plus que tous les autres, alors il est en balotage favorable, | |
* sinon infavorable. | |
*/ | |
for (i = 0; i < N_PARTICIPANTS; ++i) | |
{ | |
score = participants[i]; | |
printf("Participant %i: ", i + 1); | |
// Check de l'élimination | |
if(score < 12.5) { | |
printf("éliminé\n"); | |
continue; | |
} | |
// Check si c'est le plus haut score | |
if(score == plus_haut_score) { | |
printf("favorable\n"); | |
} | |
else { | |
printf("defavorable\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment