#39403: c++解題攻略超簡單


iant520jc@gmail.com (Ian Lin)


#include <iostream>
#include <cmath>

using namespace std;

int main(){

    int a, b, c; cin>>a>>b>>c;

    int delta = pow(b, 2) - 4*a*c;

    if (delta==0){
        int root = -b / (2*a);
        cout << "Two same roots x=" << root;

    }else if(delta>0){
        int root1 = ( -b+sqrt(delta) ) / (2*a);
        int root2 = ( -b-sqrt(delta) ) / (2*a);
        cout << "Two different roots x1=" << root1 << " , x2=" << root2;

    }else{ //delta<0
        cout << "No real root";
    }

    return 0;
}