42 lines
624 B
Plaintext
42 lines
624 B
Plaintext
------- TP08 : Boucles (suite) -------
|
|
|
|
1.
|
|
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
|
|
int main(void) {
|
|
int aleatoire;
|
|
int i;
|
|
int entree;
|
|
int VALEUR_MAX;
|
|
int NB_TENTATIVES;
|
|
VALEUR_MAX = 100;
|
|
NB_TENTATIVES = 5;
|
|
srand(time(NULL));
|
|
aleatoire = (rand() % VALEUR_MAX);
|
|
for (i = 1; i <= NB_TENTATIVES; i++) {
|
|
printf("Entrez un nombre : ");
|
|
scanf("%d", &entree);
|
|
if (entree < aleatoire) {
|
|
printf("+\n");
|
|
}
|
|
else if (entree > aleatoire) {
|
|
printf("-\n");
|
|
}
|
|
else {
|
|
printf("Bonne réponse");
|
|
}
|
|
}
|
|
if (aleatoire != entree) {
|
|
printf("Perdu");
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
|
|
-----------------------
|
|
|
|
2.
|
|
|