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

28 lines
751 B
C
Raw Normal View History

2016-01-17 19:32:46 +01:00
/* Affiche les solutions à une équation du second degré */
2016-01-17 18:39:09 +01:00
#include <stdio.h>
#include <math.h>
#include <complex.h>
2016-01-17 18:39:09 +01:00
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("%f\n", d);
2016-01-17 18:39:09 +01:00
if (d == 0) {
printf("x0 = %f", -b/2*a);
2016-01-17 18:39:09 +01:00
} else if (d > 0) {
printf("x1 = %f; x2 = %f", (-b+sqrt(d))/2*a, (-b-sqrt(d))/2*a);
2016-01-17 18:39:09 +01:00
} 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 = %f+i%f; z2 = %f+i%f\n", creal(z1), cimag(z1), creal(z2), cimag(z2));
2016-01-17 18:39:09 +01:00
}
}
return 0;
}