diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-01-31 15:39:30 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-01-31 15:39:30 +0100 |
| commit | d7c69934248f3fab4988c0d37c11feba25d653b8 (patch) | |
| tree | 6c396257cb21374e13a26b8f78c05353806220bc /semestre 2/informatique/tme/semaine1 | |
| parent | ed631f52ee7af474625e37c6855c7c55903317fc (diff) | |
Ajout du début du deuxième semestre
Diffstat (limited to 'semestre 2/informatique/tme/semaine1')
4 files changed, 103 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine1/03_jeuTest.c b/semestre 2/informatique/tme/semaine1/03_jeuTest.c new file mode 100644 index 0000000..1099c11 --- /dev/null +++ b/semestre 2/informatique/tme/semaine1/03_jeuTest.c @@ -0,0 +1,18 @@ +#include <assert.h> + +int alternative(int n1, int n2, int n3){ + int res; + if (n1 > 8) res = 3; + else if (n3 == 20) res = 2; + else if (n2 >= 10 && n3 >= 10) res = 1; + else res = 0; + return res; +} + +int main(){ + assert(alternative(-4, 3, 20) == 2); // teste de la branche n3 == 20 + assert(alternative(9,-2,20) == 3); // teste de la branche n1 > 8 + assert(alternative(-5, 15, 1098765) == 1); // teste de la branche n2 >= 10 && n3 >= 10 + assert(alternative(4, 8, 23) == 0); // teste des autres cas + return 0; +} diff --git a/semestre 2/informatique/tme/semaine1/05_discriminant.c b/semestre 2/informatique/tme/semaine1/05_discriminant.c new file mode 100644 index 0000000..575f776 --- /dev/null +++ b/semestre 2/informatique/tme/semaine1/05_discriminant.c @@ -0,0 +1,28 @@ +#include <math.h> +#include <stdio.h> + +int discriminant(int a, int b, int c){ + return b*b-4*a*c; +} + +void afficheRacines(int a, int b, int c){ + int disc = discriminant(a,b,c); + if (disc > 0) { + float sq = sqrt(disc); + printf("Racine 1 : %f\nRacine 2 : %f\n", (-b-sq)/(2*a), (-b+sq)/(2*a)); + } else if (disc == 0) { + printf("Racine double : %f\n", (-b)/(float) (2*a)); + } else { + printf("Pas de racine réelle\n"); + } +} + +int main(){ + afficheRacines(1, 1, 1); + afficheRacines(1, 1, -1); + afficheRacines(-1, 1, -1); + afficheRacines(-1, 1, 1); + afficheRacines(1, 2, 1); + afficheRacines(2, 4, 2); + return 0; +} diff --git a/semestre 2/informatique/tme/semaine1/06_signe_produit.c b/semestre 2/informatique/tme/semaine1/06_signe_produit.c new file mode 100644 index 0000000..764f184 --- /dev/null +++ b/semestre 2/informatique/tme/semaine1/06_signe_produit.c @@ -0,0 +1,20 @@ +#include <assert.h> + +int signeProduit(int a, int b){ + if (a == 0 || b == 0) return 0; + else if ( + (a < 0 && b > 0) || (a > 0 && b < 0) + ) return -1; + return 1; +} + +int main(){ + assert(signeProduit(0, 0) == 0); + assert(signeProduit(1, 0) == 0); + assert(signeProduit(0, -1) == 0); + assert(signeProduit(1, 1) == 1); + assert(signeProduit(-1, -1) == 1); + assert(signeProduit(1, -1) == -1); + assert(signeProduit(-1, 1) == -1); + return 0; +} diff --git a/semestre 2/informatique/tme/semaine1/07_tour_londres.c b/semestre 2/informatique/tme/semaine1/07_tour_londres.c new file mode 100644 index 0000000..92f0cff --- /dev/null +++ b/semestre 2/informatique/tme/semaine1/07_tour_londres.c @@ -0,0 +1,37 @@ +#include <assert.h> +#define ADU 22.7 +#define KID 10.75 +#define FAMILLY 57.8 +#define COMPARE_FLOAT_PRECISION 0.00001 + +float prixEntree(int adus, int kids){ + float no_familly = adus * ADU + kids * KID; + float with_familly = FAMILLY; + int r_adus = adus - 2; + int r_kids = kids - 3; + if (r_adus > 0){ + with_familly += r_adus * ADU; + } + if (r_kids > 0){ + with_familly += r_kids * KID; + } + if (no_familly < with_familly) return no_familly; + return with_familly; +} + +int compareFloat(float f1, float f2, float eps){ + /* Prend trois floats (f1, f2 et eps) et renvoie |f1-f2|<eps ; est une comparaison de deux + * floats à epsilon près */ + float diff = f1 - f2; + if (diff < 0) diff = - diff; + return diff < eps; +} + +int main(){ + assert(compareFloat(prixEntree(2, 3), FAMILLY, COMPARE_FLOAT_PRECISION)); + assert(compareFloat(prixEntree(2, 2), FAMILLY, COMPARE_FLOAT_PRECISION)); + assert(compareFloat(prixEntree(2, 1), 2*ADU + KID, COMPARE_FLOAT_PRECISION)); + assert(compareFloat(prixEntree(1, 3), ADU + 3*KID, COMPARE_FLOAT_PRECISION)); + assert(compareFloat(prixEntree(0, 1), KID, COMPARE_FLOAT_PRECISION)); + return 0; +} |
