From 84f95b2e59e79dc75392b344ae54cb0490d02953 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 17 Jan 2016 19:36:01 +0100 Subject: [PATCH] =?UTF-8?q?TD1E3=20Utilisation=20de=20la=20biblioth=C3=A8q?= =?UTF-8?q?ue=20standard=20des=20complexes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TP1/E3.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/TP1/E3.c b/TP1/E3.c index 5fc2afc..a21a308 100644 --- a/TP1/E3.c +++ b/TP1/E3.c @@ -1,11 +1,7 @@ /* Affiche les solutions à une équation du second degré */ #include #include - -struct Complex { - double a; // Partie réelle - double b; // Partie imaginaire -}; +#include int main() { double a, b, c; @@ -21,11 +17,9 @@ int main() { } else if (d > 0) { printf("x1 = %lf; x2 = %lf", (-b+sqrt(d))/2*a, (-b-sqrt(d))/2*a); } else { - struct Complex z1,z2; - z1.a = z2.a = pow(b,2)/2*a; - z1.b = sqrt(-d)/2*a; - z2.b = -sqrt(-d)/2*a; - printf("z1 = %lf+i%lf; z2 = %lf+i%lf\n", z1.a, z1.b, z2.a, z2.b); + double complex z1 = pow(b,2)/2*a + sqrt(-d)/2*a * I; + double complex z2 = pow(b,2)/2*a - sqrt(-d)/2*a * I; + printf("z1 = %lf+i%lf; z2 = %lf+i%lf\n", creal(z1), cimag(z1), creal(z2), cimag(z2)); } }