Description
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double a, b, c, d,e, x1, x2,t;
cin >> a >> b >> c;
d = b*b - 4 * a*c;
e=-b / (2 * a);
if (d > 0)
{
x1 = (-b - sqrt(d)) / (2 * a);
x2 = (-b + sqrt(d)) / (2 * a);
if(x1<x2)
{
t=x1;
x1=x2;
x2=t;
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<x1<<" "/*setprecision(3)*/<<x2<<endl;
}
else if (d < 0)
cout << "无解" << endl;
else
cout << setiosflags(ios::fixed)<<setprecision(2)<<e;
}
解一元二次方程
ax2+bx+c=0
的解。
Input
a,b,c 的值。
Output
两个根 x1 和 x2 ,其中 x1>=x2 结果保留两位小数