This repository has been archived on 2019-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
s4-c/TP1/E3.c

28 lines
759 B
C

/* Affiche les solutions à une équation du second degré */
#include <stdio.h>
#include <math.h>
#include <complex.h>
int main() {
double a, b, c;
printf("Saisissez les réels a≠0, b et c séparés par une virgule\n");
scanf("%lf,%lf,%lf", &a, &b, &c);
if (a == 0) {
printf("On a dit a≠0 !\n");
} else {
double d = pow(b,2)-4*a*c;
printf("%lf\n", d);
if (d == 0) {
printf("x0 = %lf", -b/2*a);
} else if (d > 0) {
printf("x1 = %lf; x2 = %lf", (-b+sqrt(d))/2*a, (-b-sqrt(d))/2*a);
} else {
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));
}
}
return 0;
}