Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
68
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 <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.     double a, b, c;  
  8.     cin >> a >> b >> c;
  9.  
  10.     int d;
  11.  
  12.     d = b * b - (4 * a* c);
  13.  
  14.     double x1, x2;
  15.     x1 = (-b + sqrt(d)) / (2 * a);
  16.  
  17.     x2 = (-b - sqrt(d)) / (2 * a);
  18.  
  19.     if (d < 0) {
  20.         cout << "no roots" << endl;
  21.     }
  22.     else if (x1 == x2) {
  23.         cout << x1;
  24.     }
  25.     else {
  26.         if (x1 != 0) {
  27.             cout << x1 << " ";
  28.         }
  29.         if (x2 != 0) {
  30.             cout << x2;
  31.         }
  32.     }
  33.  
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement