Advertisement
uopspop

Untitled

Apr 19th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main(){
  7.     int a, b, c;
  8.     cin >> a >> b >> c;
  9.     int x1, x2;
  10.     int cal0 = b*b - 4*a*c; // 判斷式
  11.    
  12.     int cal1 = sqrt(b*b - 4*a*c);
  13. //  cout << b*b - 4*a*c << endl;
  14. //  cout << cal1 << endl;
  15.     x1 = (-b + cal1) / (a*2);
  16.     x2 = (-b - cal1) / (a*2);
  17. //  cout << x1  << endl;
  18. //  cout << x2 << endl;
  19.        
  20.     if (cal0 < 0){
  21.         cout << "No real root" << endl;
  22.         return 0;      
  23.     }else if(cal0 == 0){
  24.         cout << "Two same roots x=" << x1 << endl; 
  25.     }else{
  26.         cout << "Two different roots x1=" << x1 << " , x2=" << x2 << endl; 
  27.     }
  28.    
  29. /*
  30. Two different roots x1=2 , x2=-5
  31. Two same roots x=0
  32. No real root
  33.  
  34. */ 
  35.    
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement