题目链接
注意特殊情况
当a等于0和b等于0时,因为都有可能放在分母!
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,c;
while(cin>>n){
while(n--){
cin>>a>>b>>c;
int delta = b*b-4*a*c;
if(a==0&&b!=0) printf("x=%.2f\n",-c*1.0/b);
else if(delta>0){
double x1 = (-b-sqrt(delta))/2.0/a;
double x2 = (-b+sqrt(delta))/2.0/a;
printf("x1=%.2f,x2=%.2f\n",x1,x2);
}else if(delta==0){
double x = (-b)/2.0/a;
printf("x=%.2f\n",x);
}else cout<<"-1\n";
}
}
return 0;
}