题目要求是求a^4+b^2+c=0的根。
在测试的时候把a=1,b=0,c=0带入正确输出应该是0,但是我的代码输出为no solution。
a=1,b=-6,c=9的时候输出也是no solution,和正确答案不一样。
找了好半天也没看出哪里有错来,想让大家帮忙看一下,谢谢!
#include
#include
using namespace std;
int main()
{
double a,b,c;
cout<<"Enter the coefficient a:"< cin>>a;
cout<<"Enter the coefficient b:"< cin>>b;
cout<<"Enter the coefficient c:"< cin>>c;
double d=pow(b,2)-4*a*c;
if(d>0)
{
double w1=(-b+sqrt(d))/(2*a);
if(w1>0)
{
double x1=sqrt(w1);
double x2=-sqrt(w1);
cout<<"This bi-quadratic equation has the following solutions: "< }
else if(w1==0)
{
double x1=sqrt(w1);
cout }
else
{
cout }
double w2=(-b-sqrt(d))/(2*a);
if(w2>0)
{
double x1=sqrt(w2);
double x2=-sqrt(w2);
cout<<"This bi-quadratic equation has the following solutions: "< }
else if(w2==0)
{
double x1=sqrt(w2);
cout }
else
{
cout }
}
else if(d=0)
{
double w1=(-b)/(2*a);
if (w1>0)
{
double x1=sqrt(w1);
double x2=-sqrt(w1);
cout<<"This bi-quadratic equation has the following solutions: "<<x1<<" and "<<x2<<endl;
}
else if(w1==0)
{
double x1=sqrt(w1);
cout<<"This bi-quadratic equation has the following solutions: "<<x1<<endl;
}
else
{
cout<<"This bi-quadratic equation has no solutions"<<endl;
}
}
else
{
cout<<"This bi-quadratic equation has no solutions"<<endl;
}
system("Pause");
return 0;
}
单步调试一下。
if(d>=0)