-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhuongTrinhTrungPhuong.cpp
144 lines (140 loc) · 4.27 KB
/
PhuongTrinhTrungPhuong.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double a, b, c;
cin >> a >> b >> c;
double delta;
double nghiem1, nghiem2;
if (a == 0 && b == 0)
{
if (c == 0)
{
cout << "phuong trinh co vo so nghiem";
}
if (c != 0)
{
cout << "phuong trinh vo nghiem";
}
}
else if (a == 0 && b != 0)
{
if (c == 0)
{
nghiem1 = 0;
cout << "phuong trinh co 1 nghiem " << endl;
cout << fixed << showpoint << setprecision(5);
cout << nghiem1;
}
if (c != 0)
{
if (c > 0)
{
cout << "phuong trinh vo nghiem";
}
else if (c < 0)
{
nghiem1 = sqrt((-c) / b);
cout << "phuong trinh co 2 nghiem" << endl;
cout << -nghiem1 << " " << nghiem1;
}
}
}
else if (a != 0 && b == 0)
{
if (c == 0)
{
nghiem1 = 0;
cout << "phuong trinh co 1 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << nghiem1;
}
if (c != 0)
{
if (c < 0)
{
nghiem1 = sqrt((-c) / a);
cout << "phuong trnh co 2 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << -nghiem1 << " " << nghiem1;
}
if (c > 0)
{
cout << "phuong trinh vo nghiem";
}
}
}
else if (a != 0 && b != 0)
{
if (c == 0)
{
if (b < 0)
{
nghiem1 = 0;
nghiem2 = double(-b) / double(a);
cout << "phuong trinh co 3 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << -sqrt(nghiem2) << " " << nghiem1 << " " << sqrt(nghiem2);
}
if (b > 0)
{
nghiem1 = 0;
cout << "phuong trinh co 1 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << nghiem1 << endl;
}
}
if (c != 0)
{
delta = b * b - 4 * a * c;
if (delta < 0)
{
cout << "phuong trinh vo nghiem";
}
if (delta == 0)
{
if ((-b) / (2 * a) > 0)
{
nghiem1 = sqrt((-b) / (2 * a));
cout << "phuong trinh co 2 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << -nghiem1 << " " << nghiem1;
}
if ((-b) / (2 * a) < 0)
{
cout << "phuong trinh vo nghiem";
}
}
if (delta > 0)
{
nghiem1 = (-b - sqrt(delta)) / (2 * a);
nghiem2 = (-b + sqrt(delta)) / (2 * a);
if (nghiem1 > 0 && nghiem2 > 0)
{
cout << "phuong trinh co 4 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << -sqrt(nghiem2) << " " << -sqrt(nghiem1) << " " << sqrt(nghiem1) << " " << sqrt(nghiem2);
}
if (nghiem1 > 0 && nghiem2 < 0)
{
cout << "phuong trinh co 2 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << -sqrt(nghiem1) << " " << sqrt(nghiem1);
}
if (nghiem1 < 0 && nghiem2 > 0)
{
cout << "phuong trinh co 2 nghiem" << endl;
cout << fixed << showpoint << setprecision(5);
cout << -sqrt(nghiem2) << " " << sqrt(nghiem2);
}
if (nghiem1 < 0 && nghiem2 < 0)
{
cout << "phuong trinh vo nghiem";
}
}
}
}
return 0;
}