Skip to content

Instantly share code, notes, and snippets.

@PifyZ
Created August 3, 2014 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PifyZ/2953183b414864abc601 to your computer and use it in GitHub Desktop.
Save PifyZ/2953183b414864abc601 to your computer and use it in GitHub Desktop.
Plus ou moins
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main (int argc, char *argv[]) {
srand(time(NULL));
int nb_rand = rand() % 100;
int saisie = -1;
int nb_essais = 0;
do {
printf("Essai n%d = ", nb_essais + 1);
scanf("%d", &saisie);
nb_essais++;
if (saisie > nb_rand)
printf("C'est moins.\n");
if (saisie < nb_rand)
printf("C'est plus.\n");
} while (saisie != nb_rand);
printf("Victoire ! En %d essais.", nb_essais);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment