C++求一元二次方程的根的程序总是运行不出正确结果,请各位高手帮忙看程序错在哪里,非常感谢
#include<stdio.h>#include<math.h>voidmain(){doublea,b,c,d;printf("输入一元二次方程a=,b=,c=\n"...
#include <stdio.h>
#include <math.h>
void main()
{
double a,b,c,d;
printf("输入一元二次方程 a=,b=,c=\n");
scanf("a=%f,b=%f,c=%f",&a,&b,&c);
d=b*b-4*a*c;
if(a==0)
{
if(b=0)
{if(c==0)
printf("0==0参数对方程无意义!");
else
printf("c!=0方程不成立!");
}
else
printf("x=%0.2f\n",-c/b);
}
else
if(d>=0)
{printf("x1=%0.2f\n",(-b+sqrt(d))/(2*a));
printf("x2=%0.2f\n",(-b-sqrt(d))/(2*a));
}
else{
printf("x1=%0.2f+%0.2fi\n",-b/(2*a),sqrt(-d)/(2*a));
printf("x2=%0.2f-%0.2fi\n",-b/(2*a),sqrt(-d)/(2*a));
}
} 展开
#include <math.h>
void main()
{
double a,b,c,d;
printf("输入一元二次方程 a=,b=,c=\n");
scanf("a=%f,b=%f,c=%f",&a,&b,&c);
d=b*b-4*a*c;
if(a==0)
{
if(b=0)
{if(c==0)
printf("0==0参数对方程无意义!");
else
printf("c!=0方程不成立!");
}
else
printf("x=%0.2f\n",-c/b);
}
else
if(d>=0)
{printf("x1=%0.2f\n",(-b+sqrt(d))/(2*a));
printf("x2=%0.2f\n",(-b-sqrt(d))/(2*a));
}
else{
printf("x1=%0.2f+%0.2fi\n",-b/(2*a),sqrt(-d)/(2*a));
printf("x2=%0.2f-%0.2fi\n",-b/(2*a),sqrt(-d)/(2*a));
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询