Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- int main()
- {
- double a, b, c, D, x1, x2;
- cin >> a >> b >> c;
- D = b * b - 4 * a * c;
- if ((a == 0 && c == 0) || (b == 0 && c == 0))
- {
- cout << 0;
- }
- else if (a == 0)
- {
- cout << -(c / b);
- }
- else if (b == 0)
- {
- cout << " ";
- }
- else if (c == 0)
- {
- cout << 0 << " " << -(b / a);
- }
- else if (D < 0)
- {
- cout << " ";
- }
- else if (D == 0)
- {
- x1 = ((-1 * b) + sqrt(D)) / (2 * a);
- cout << x1;
- }
- else if (D > 0)
- {
- x1 = ((-1 * b) + sqrt(D)) / (2 * a);
- x2 = ((-1 * b) - sqrt(D)) / (2 * a);
- cout << x1 << " " << x2;
- }
- }
- //#include<iostream>
- //#include<cmath>
- //
- //using namespace std;
- //
- //void SolveQuadraticEquation(double a, double b, double c)
- //{
- //
- //}
- //void SolveLinearEquation(double b, double c)
- //{
- // // b * x + c = 0
- // if (b != 0)
- // {
- // cout << -c / b;
- // }
- //}
- //
- //int main()
- //{
- // double a, b, c;
- // cin >> a >> b >> c;
- //
- // if (a != 0)
- // {
- // SolveQuadraticEquation(a, b, c);
- // }
- // else
- // {
- // SolveLinearEquation(b, c);
- // }
- // return 0;
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement