-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrinome.c
48 lines (38 loc) · 858 Bytes
/
trinome.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* trinome2.c
un programme simple de calcul des racines d'un trinôme
gcc -o trinome2 -lm trinome2.c
Time-stamp: <2006-03-28 22:36:10 chl> */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static double EPS = 1E-10;
int main(void)
{
float a, b, c = 0.0;
float delta = 0.0;
float r1, r2, i1, i2 = 0.0;
printf("a = ");
scanf("%g",&a);
printf("b = ");
scanf("%g",&b);
printf("c = ");
scanf("%g",&c);
delta = b*b - 4*a*c;
if (delta >= 0) {
if (b > 0)
r1 = -(b+sqrt(delta))/(2*a);
else
r1 = (-b+sqrt(delta))/(2*a);
r2 = abs(r1) < EPS ? 0 : c/(a*r1);
i1 = i2 = 0;
}
else {
r1 = r2 = -b/(2*a);
i1 = sqrt(-delta)/(2*a);
i2 = -i1;
}
//printf("delta = %g\n", delta);
printf("\nx1 = %g + %g*i\n", r1, i1);
printf("x2 = %g + %g*i\n", r2, i2);
return EXIT_SUCCESS;
}