From 33bfc43144a8b5ba102988f8c734607d5221193b Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Fri, 24 Sep 2021 10:19:20 +0200 Subject: [PATCH] TP06 Conditions --- APL1.1/TP06/couverture.c | 39 ++++++++++++++++++++++++++++++++++++++ APL1.1/TP06/maximum.c | 41 ++++++++++++++++++++++++++++++++++++++++ APL1.1/TP06/mention.c | 28 +++++++++++++++++++++++++++ APL1.1/TP06/ordre.c | 37 ++++++++++++++++++++++++++++++++++++ APL1.1/TP06/produit.c | 23 ++++++++++++++++++++++ APL1.1/TP06/triple.c | 32 +++++++++++++++++++++++++++++++ 6 files changed, 200 insertions(+) create mode 100644 APL1.1/TP06/couverture.c create mode 100644 APL1.1/TP06/maximum.c create mode 100644 APL1.1/TP06/mention.c create mode 100644 APL1.1/TP06/ordre.c create mode 100644 APL1.1/TP06/produit.c create mode 100644 APL1.1/TP06/triple.c diff --git a/APL1.1/TP06/couverture.c b/APL1.1/TP06/couverture.c new file mode 100644 index 0000000..214e34d --- /dev/null +++ b/APL1.1/TP06/couverture.c @@ -0,0 +1,39 @@ +#include +#include + +int min(int a, int b) { + return a < b ? a : b; +} + +int max(int a, int b) { + return a > b ? a : b; +} + +int main(int argc, char * argv[]) { + int frais, result; + printf("Veuillez indiquer le montant total des réparations : "); + result = scanf("%d", &frais); + + if (result != 1) { + printf("Format invalide.\n"); + return EXIT_FAILURE; + } + + int part_assure, part_assurance; + + if ( frais <= 200 ) { + part_assure = frais; + part_assurance = 0; + } else if (frais <= 2000) { + part_assure = 200; + part_assurance = frais - 200; + } else { + part_assure = min(frais/10, 800); + part_assurance = frais - part_assure; + } + + printf("L'assuré prendra en charge %d€ et l'assurance %d€.\n", part_assure, part_assurance); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP06/maximum.c b/APL1.1/TP06/maximum.c new file mode 100644 index 0000000..40d6a83 --- /dev/null +++ b/APL1.1/TP06/maximum.c @@ -0,0 +1,41 @@ +#include +#include + +int proposeInt() { + printf("Veuillez donner un entier : "); +} + +int checkResult(int result) { + if (result == 0) { + printf("Format Incorrect.\n"); + return 0; + } + + return 1; +} + +int main(int argc, char * argv[]) { + int max, min; + printf("%d", &max); + + proposeInt(); + int result1 = scanf("%d", &max); + if (!checkResult(result1)) return EXIT_FAILURE; + + proposeInt(); + int result2 = scanf("%d", &min); + if (!checkResult(result2)) return EXIT_FAILURE; + + max = max>min ? max : min; + + proposeInt(); + int result3 = scanf("%d", &min); + if (!checkResult(result3)) return EXIT_FAILURE; + + max = max>min ? max : min; + + printf("Le maximum de ces trois valeurs est %d.\n", max); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP06/mention.c b/APL1.1/TP06/mention.c new file mode 100644 index 0000000..deaa51b --- /dev/null +++ b/APL1.1/TP06/mention.c @@ -0,0 +1,28 @@ +#include +#include + +int main(int argc, char * argv[]) { + int note, result; + + printf("Veuillez donner votre note du Bac : "); + result = scanf("%d", ¬e); + + if (result == 1) { + if (note >= 16) { + printf("Vous avez eu le bac avec mention 'Très Bien', féliciations.\n"); + } else if (note >= 14) { + printf("Vous avez eu le bac avec mention 'Bien', bon travail.\n"); + } else if (note >= 12) { + printf("Vous avez eu le bac avec mention 'Assez Bien', satisfaisant.\n"); + } else { + printf("Vous avez eu le bac sans mention.. Triste.\n"); + } + + return EXIT_SUCCESS; + } else { + printf("Format invalide.\n"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP06/ordre.c b/APL1.1/TP06/ordre.c new file mode 100644 index 0000000..58bc8ce --- /dev/null +++ b/APL1.1/TP06/ordre.c @@ -0,0 +1,37 @@ +#include +#include + +int main(int argc, char * argv[]) { + int int1, int2, int3, result; + + printf("Veuillez donner trois entiers : "); + result = scanf("%d %d %d", &int1, &int2, &int3); + + if (result != 3) { + printf("Format invalide.\n"); + return EXIT_FAILURE; + } + + if (int1 > int2) { + int temp_int = int1; + int1 = int2; + int2 = temp_int; + } + + if (int1 > int3) { + int temp_int = int1; + int1 = int3; + int3 = temp_int; + } + + if (int2 > int3) { + int temp_int = int2; + int2 = int3; + int3 = temp_int; + } + + printf("Dans l'ordre croissant : %d, %d, %d.\n", int1, int2, int3); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP06/produit.c b/APL1.1/TP06/produit.c new file mode 100644 index 0000000..40c2d8d --- /dev/null +++ b/APL1.1/TP06/produit.c @@ -0,0 +1,23 @@ +#include +#include + +int main(int argc, char * argv[]) { + int arg1, arg2, result; + printf("Veuillez entrer deux entiers :"); + result = scanf("%d %d", &arg1, &arg2); + + if (result == 2) { + if ((arg1 < 0 || arg2 < 0) && !(arg1 < 0 && arg2 < 0)) { + //On print le résultat pour vérifier. + printf("Le résultat sera négatif (%d).\n", arg1 * arg2); + return EXIT_SUCCESS; + } else { + printf("Le résultat sera positif (%d).\n", arg1 * arg2); + } + } else { + printf("Format incorrect.\n"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP06/triple.c b/APL1.1/TP06/triple.c new file mode 100644 index 0000000..8c1dfdc --- /dev/null +++ b/APL1.1/TP06/triple.c @@ -0,0 +1,32 @@ +#include +#include + +int main(int argc, char * argv[]) { + printf("Veuillez donner un entier naturel : "); + int entier, result; + result = scanf("%d", &entier); + + if (entier < 0) { + printf("L'entier doit être supérieur ou égal à 0.\n"); + return EXIT_FAILURE; + } + + if (result == 1) { + int remainder = entier % 3; + int triple; + if (remainder == 0) { + triple = entier; + } else if (remainder == 1) { + triple = entier - 1; + } else { + triple = entier + 1; + } + + printf("Le multiple de trois le plus proche est %d.\n", triple); + } else { + printf("Format invalide.\n"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} +