diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-02-13 17:42:52 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-02-13 17:42:52 +0100 |
| commit | a1a5447b8b040b100bad89766066ae4ba8d6d920 (patch) | |
| tree | f255a6da6b6af8daa1906bd834131052b64a2ca5 /semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c | |
| parent | 755d27882e2cb21a5e30b6854bea8e4454f2328d (diff) | |
Ajout de la semaine des cours du 7 au 13 février
Diffstat (limited to 'semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine3/18_tri_trois_valeurs.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 <assert.h> + +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); +} |
