forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbai1.9.c
More file actions
33 lines (30 loc) · 771 Bytes
/
bai1.9.c
File metadata and controls
33 lines (30 loc) · 771 Bytes
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
#include <stdio.h>
#include <math.h>
int main() {
float a, c, b, delta, x1, x2, x;
printf("Nhap vao cac he so phuong trinh bac hai: ");
scanf("%f%f%f", &a, &b, &c);
if(a == 0) { // PT bac 1
if(b == 0 && c != 0) {
printf("Phuong trinh vo nghiem\n");
} else if(b == 0 && c == 0) {
printf("Phuong trinh co vo so nghiem\n");
} else {
x = -c / b;
printf("Nghiem phuong trinh = %0.2f", x);
}
} else { // PT bac 2
delta = b * b - a * c * 4;
if(delta < 0) {
printf("PT vo nghiem");
} else if(delta == 0) {
x1 = -b/(2 * a);
printf("PT co nghiem kep x = %0.2f", x1);
} else {
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
printf("Nghiem PT la: \nx1 = %0.2f\nx2 = %0.2f", x1, x2);
}
}
return 0;
}