-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path8.cpp
More file actions
29 lines (24 loc) · 909 Bytes
/
8.cpp
File metadata and controls
29 lines (24 loc) · 909 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
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c;
cout << "Enter coefficients (a, b, c): ";
cin >> a >> b >> c;
double discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
double root1 = (-b + sqrt(discriminant)) / (2 * a);
double root2 = (-b - sqrt(discriminant)) / (2 * a);
cout << "Root 1: " << root1 << endl;
cout << "Root 2: " << root2 << std::endl;
} else if (discriminant == 0) {
double root1 = -b / (2 * a);
cout << "Root 1 and Root 2 are real and equal: " << root1 << endl;
} else {
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-discriminant) / (2 * a);
cout << "Root 1: " << realPart << " + " << imaginaryPart << "i" << endl;
cout << "Root 2: " << realPart << " - " << imaginaryPart << "i" << endl;
}
return 0;
}