QwideEdits

Untitled

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