Problem Description
解一元二次方程ax2+bx+c=0的解。保证有解
Input
a,b,c的值。
Output
两个根X1和X2,其中X1>=X2。 结果保留两位小数。
Sample Input
1 5 -2
Sample Output
0.37 -5.37
Hint
提示:计算过程中,分母是(2*a)
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double a,b,c;
double x1,x2,s,t;
cin>>a>>b>>c;
s=sqrt(b*b-4*a*c);
x1=(-b+s)/(2*a);
x2=(-b-s)/(2*a);
if(x1<x2)
{
t=x1;
x1=x2;
x2=t;
}//必定要有这一步,不然不通过
printf("%.2lf %.2lf",x1,x2);
return 0;
}