Advertisement
Spocoman

03. Quadratic Equation

Oct 25th, 2023 (edited)
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     double a, b, c;
  8.     cin >> a >> b >> c;
  9.  
  10.     double d = pow(b, 2) - 4 * a * c;
  11.     double x1 = (-b + sqrt(d)) / (2 * a);
  12.     double x2 = (-b - sqrt(d)) / (2 * a);
  13.  
  14.     if (d < 0) {
  15.         cout << "no roots" << endl;
  16.     }
  17.     else if (d == 0) {
  18.         cout << -b / (2 * a) << endl;
  19.     }
  20.     else {
  21.         cout << x1 << " " << x2 << endl;
  22.     }
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement