求一元二次方程,为什么错
程序代码:
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ double a,b,c,d,x1,x2; cin>>a>>b>>c; x1=(-b+sqrt(b*b-4*a*c))/(2*a); x2=(-b-sqrt(b*b-4*a*c))/(2*a); d=b*b-4*a*c; if(d<0){ cout<<"No answer!"; } else{ if(x1==x2){ printf("x1=x2=%.5f",x1); } else{ if(x1>x2){ printf("x2=%.5f;x1=%.5f",x2,x1); } if(x1<x2){ printf("x1=%.5f;x2=%.5f",x1,x2); } } } return 0; }
题目链接:http://ybt.