From ab52c402233e8279191c93f9c3e68cf441059632 Mon Sep 17 00:00:00 2001 From: Simoes Lukas Date: Tue, 17 Sep 2024 17:31:02 +0200 Subject: [PATCH] TP --- DEV1.1/TP08/TP08_reponses.txt | 41 +++++++++++++++++++++++++++++++++++ DEV1.1/TP08/tests.c | 31 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 DEV1.1/TP08/TP08_reponses.txt create mode 100644 DEV1.1/TP08/tests.c diff --git a/DEV1.1/TP08/TP08_reponses.txt b/DEV1.1/TP08/TP08_reponses.txt new file mode 100644 index 0000000..1dc735d --- /dev/null +++ b/DEV1.1/TP08/TP08_reponses.txt @@ -0,0 +1,41 @@ +------- TP08 : Boucles (suite) ------- + +1. + +# include +# include + +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. + diff --git a/DEV1.1/TP08/tests.c b/DEV1.1/TP08/tests.c new file mode 100644 index 0000000..9155bc5 --- /dev/null +++ b/DEV1.1/TP08/tests.c @@ -0,0 +1,31 @@ +# include +# include + +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; +} \ No newline at end of file