#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a, b, c, D, R1, R2;
while(cin>>a>>b>>c)
{
D = b*b - 4*a*c;
R1 = (-b + sqrt(D)) / 2*a;
R2 = (-b - sqrt(D)) / 2*a;
if(D<0)
{
cout << "No real root" << endl;
}
else if(D==0)
{
cout << "Two same roots x=" << R1 << endl;
}
else if(D>0)
{
cout << "Two different roots x1=" << R1 << " , x2=" << R2 << endl;
}
}
return 0;
}
#include
#include
using namespace std;
int main()
{
int a, b, c, D, R1, R2;
while(cin>>a>>b>>c)
{
D = b*b - 4*a*c;
R1 = (-b + sqrt(D)) / 2*a;
R2 = (-b - sqrt(D)) / 2*a;
if(D<0)
{
cout << "No real root" << endl;
}
else if(D==0)
{
cout << "Two same roots x=" << R1 << endl;
}
else if(D>0)
{
cout << "Two different roots x1=" << R1 << " , x2=" << R2 << endl;
}
}
return 0;
}
R1 = (-b + sqrt(D)) /( 2*a);
R2 = (-b - sqrt(D)) /( 2*a);
沒括號變成除以2後再乘以a