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 --- .../tme/semaine3/18_tri_trois_valeurs.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c (limited to 'semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c') diff --git a/semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c b/semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c new file mode 100644 index 0000000..cfea419 --- /dev/null +++ b/semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c @@ -0,0 +1,38 @@ +#include + +void echange(int *a, int *b){ + int t = *a; + *a = *b; + *b = t; +} + +void tri(int *a, int *b){ + if (*a <= *b) return; + echange(a,b); +} + +void tri_3(int *a, int *b, int *c){ + tri(a, b); + tri(a, c); + tri(b, c); +} + +int main(){ + int a = 2, b = 5; + echange(&a, &b); + assert(a == 5); + assert(b == 2); + tri(&a, &b); + assert(a == 2); + assert(b == 5); + int c = 8; + a = 4; b = 2; + tri_3(&a, &b, &c); + assert(a == 2 && b == 4 && c == 8); + a = 2; b = 4; c = 8; + tri_3(&a, &b, &c); + assert(a == 2 && b == 4 && c == 8); + a = 8; b = 4; c = 2; + tri_3(&a, &b, &c); + assert(a == 2 && b == 4 && c == 8); +} -- cgit v1.2.3