aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine1/05_discriminant.c
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-01-31 15:39:30 +0100
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-01-31 15:39:30 +0100
commitd7c69934248f3fab4988c0d37c11feba25d653b8 (patch)
tree6c396257cb21374e13a26b8f78c05353806220bc /semestre 2/informatique/tme/semaine1/05_discriminant.c
parented631f52ee7af474625e37c6855c7c55903317fc (diff)
Ajout du début du deuxième semestre
Diffstat (limited to 'semestre 2/informatique/tme/semaine1/05_discriminant.c')
-rw-r--r--semestre 2/informatique/tme/semaine1/05_discriminant.c28
1 files changed, 28 insertions, 0 deletions
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;
+}