TD1E3 Utilisation de la bibliothèque standard des complexes

This commit is contained in:
Geoffrey Frogeye 2016-01-17 19:36:01 +01:00
parent 600cc0bb6b
commit 84f95b2e59

View file

@ -1,11 +1,7 @@
/* Affiche les solutions à une équation du second degré */
#include <stdio.h>
#include <math.h>
struct Complex {
double a; // Partie réelle
double b; // Partie imaginaire
};
#include <complex.h>
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));
}
}