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

34 lines
725 B
C

/* Programme qui lit et affiche les caractères */
#include <stdio.h>
#include <math.h>
struct Complex {
double a;
double b;
};
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 {
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);
}
}
return 0;
}