-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path090-SolveQuadEqn.cpp
More file actions
34 lines (28 loc) · 850 Bytes
/
090-SolveQuadEqn.cpp
File metadata and controls
34 lines (28 loc) · 850 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
34
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Enter a, b, c (for ax^2 + bx + c): ";
int a, b, c;
cin >> a >> b >> c;
int d = b * b - 4 * a * c;
if (d < 0)
{
cout << "Roots are complex number." << endl;
printf("Roots of quadratic equation are: ");
printf("%.3f%+.3fi", -b / (2 * a), sqrt(-d) / (2 * a));
printf(", %.3f%+.3fi", -b / (2 * a), -sqrt(-d) / (2 * a));
return 0;
}
else if (d == 0)
{
cout << "Both roots are equal." << endl;
printf("Root of quadratic equation is: %.3f ", -b / (2 * a));
}
else
{
cout << "Roots are real numbers." << endl;
printf("Roots of quadratic equation are: %.3f , %.3f\n", (-b + sqrt(d)) / (2 * a), (-b - sqrt(d)) / (2 * a));
}
return 0;
}