From d7c69934248f3fab4988c0d37c11feba25d653b8 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 31 Jan 2025 15:39:30 +0100 Subject: =?UTF-8?q?Ajout=20du=20d=C3=A9but=20du=20deuxi=C3=A8me=20semestre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatique/tme/semaine2/14_tour_londres.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 semestre 2/informatique/tme/semaine2/14_tour_londres.c (limited to 'semestre 2/informatique/tme/semaine2/14_tour_londres.c') diff --git a/semestre 2/informatique/tme/semaine2/14_tour_londres.c b/semestre 2/informatique/tme/semaine2/14_tour_londres.c new file mode 100644 index 0000000..1c86e65 --- /dev/null +++ b/semestre 2/informatique/tme/semaine2/14_tour_londres.c @@ -0,0 +1,51 @@ +#include +#define ADU 22.7 +#define KID 10.75 +#define FAMILLY 57.8 +#define MAX_ADU_FAMILLY 2 +#define MAX_KID_FAMILLY 3 +#define COMPARE_FLOAT_PRECISION 0.00001 + +float prixEntree(int adus, int kids){ + int max_familly = 0; + int r_adus = adus; + int r_kids = kids; + do { + r_adus -= MAX_ADU_FAMILLY; + r_kids -= MAX_KID_FAMILLY; + max_familly++; + } while (r_adus > 0 || r_kids > 0); + float min = -1; + for (int f = 0; f <= max_familly; f++){ + int r_adus = adus - MAX_ADU_FAMILLY*f; + int r_kids = kids - MAX_KID_FAMILLY*f; + float t = f*FAMILLY; + if (r_adus > 0) t += r_adus * ADU; + if (r_kids > 0) t += r_kids * KID; + if (min == -1 || t < min) { + min = t; + } + } + return min; +} + +int compareFloat(float f1, float f2, float eps){ + /* Prend trois floats (f1, f2 et eps) et renvoie |f1-f2|