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)); } }