这道题简单,在OpenJudge上有一道更难的,网址
http://noi.openjudge.cn/ch0104/20/
打得有问题,求各位大神看一下
我打的代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
double a,b,c;
cin>>a>>b>>c;
double x1,x2;
cout<<fixed<<setprecision(5);
if(b*b<4*a*b){
x1=(-b/(2.0*a))+(sqrt(4.0*a*c-b*b)/(2.0*a));
x2=(-b/(2.0*a))-(sqrt(4.0*a*c-b*b)/(2.0*a));
printf("x1=%lf+%lfi;x2=%lf-%lfi",-b/(2.0*a),sqrt(4.0*a*c-b*b)/(2.0*a),-b/(2.0*a),(sqrt(4.0*a*c-b*b)/(2.0*a)));
return 0;
}
if(b*b>4*a*c){
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("x1=%lf;x2=%lf",x1,x2);
return 0;
}
if(b*b==4*a*c){
printf("x1=x2=%lf",(-b+sqrt(b*b-4*a*c))/(2*a));
return 0;
}
return 0;
}