Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main(){
- int a, b, c;
- cin >> a >> b >> c;
- int x1, x2;
- int cal0 = b*b - 4*a*c; // 判斷式
- int cal1 = sqrt(b*b - 4*a*c);
- // cout << b*b - 4*a*c << endl;
- // cout << cal1 << endl;
- x1 = (-b + cal1) / (a*2);
- x2 = (-b - cal1) / (a*2);
- // cout << x1 << endl;
- // cout << x2 << endl;
- if (cal0 < 0){
- cout << "No real root" << endl;
- return 0;
- }else if(cal0 == 0){
- cout << "Two same roots x=" << x1 << endl;
- }else{
- cout << "Two different roots x1=" << x1 << " , x2=" << x2 << endl;
- }
- /*
- Two different roots x1=2 , x2=-5
- Two same roots x=0
- No real root
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement