Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cmath>
  4. using namespace std;
  5. int main()
  6. {
  7.     double a;
  8.     double b;
  9.     double c;
  10.  
  11.     cin >> a;
  12.     cin >> b;
  13.     cin >> c;
  14.  
  15.     double Discriminant = (b * b) - 4 * a * c;
  16.  
  17.     double sqrtDiscriminant = sqrt(Discriminant);
  18.  
  19.     double firstRoot = (-b - sqrtDiscriminant) / (2 * a);
  20.     double secondRoot= (-b + sqrtDiscriminant) / (2 * a);
  21.  
  22.     if (Discriminant > 0)
  23.     {
  24.         cout << secondRoot << " " << firstRoot << endl;
  25.     }
  26.     else if (Discriminant == 0)
  27.     {
  28.         cout << firstRoot << endl;
  29.     }
  30.     else
  31.     {
  32.         cout << "no roots" << endl;
  33.     }
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement