From a1a5447b8b040b100bad89766066ae4ba8d6d920 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 13 Feb 2025 17:42:52 +0100 Subject: =?UTF-8?q?Ajout=20de=20la=20semaine=20des=20cours=20du=207=20au?= =?UTF-8?q?=2013=20f=C3=A9vrier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatique/tme/semaine3/19_moyenne_min_max.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 semestre 2/informatique/tme/semaine3/19_moyenne_min_max.c (limited to 'semestre 2/informatique/tme/semaine3/19_moyenne_min_max.c') diff --git a/semestre 2/informatique/tme/semaine3/19_moyenne_min_max.c b/semestre 2/informatique/tme/semaine3/19_moyenne_min_max.c new file mode 100644 index 0000000..11c66db --- /dev/null +++ b/semestre 2/informatique/tme/semaine3/19_moyenne_min_max.c @@ -0,0 +1,51 @@ +#include +#include +#define VAL1 12 +#define VAL2 7 +#define VAL3 5 +#define VAL4 9 + +void min_max(int *min, int *max, int v){ + if (v > *max) *max = v; + if (v < *min) *min = v; +} + +void stats(float*moy, int*max, int*min, int a, int b, int c, int d){ + if (a < 0) return; + int sum = a; + *min = a; + *max = a; + if (b < 0) { + *moy = a; + return; + } + sum += b; + min_max(min, max, b); + if (c < 0) { + *moy = sum/ (float) 2; + return; + } + sum += c; + min_max(min, max, c); + if (d < 0){ + *moy = sum/ (float) 3; + return; + } + sum += d; + min_max(min, max, d); + *moy = sum/ (float) 4; +} + +void afficher_resultat(float moyenne, int min, int max){ + printf("max = %d, min = %d, moy = %.2f\n",max,min,moyenne); +} + +int main(){ + float moy = -1; + int min, max = -1; + + stats(&moy, &max, &min, VAL1, VAL2, VAL3, VAL4); + + afficher_resultat(moy, min, max); + return 0; +} -- cgit v1.2.3