#include <iostream>
#include <cmath>
using namespace std;
int f(double a,double b,double c,double &x1,double &x2);
int main()
{
double a,b,c,x1,x2;
cin>>a>>b>>c;
if(f(a,b,c,x1,x2)==0)
cout<<"无实数根"<<endl;
else
if(x1<=x2)
cout<<x1<<","<<x2<<endl;
else
cout<<x2<<","<<x1<<endl;
return 0;
}
int f(double a,double b,double c,double &x1,double &x2)
{
double d=b*b-4*a*c;
if(d<0)
return 0;
d=sqrt(d);
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
if(d>0)
return 2;
else
return 1;
}
求一元二次方程
最新推荐文章于 2020-06-15 12:20:13 发布