#include "stdio.h"
#include "math.h"
void root(double a,double b,double c)
{
double d=b*b-4*a*c;
if (a=0)
{printf("这不是一元二次方程! ");}
else {if (d>0)
{printf("X1=%.2lf ", (-b+sqrt(d))/(2*a));
printf("X2=%.2lf ", (-b-sqrt(d))/(2*a));}
else {if (d=0)
printf("X=%.2f ",-b/(2*a));
else
printf("实部为%lf ",-b/2*a);
printf("虚部为%lf ",+(sqrt(-d))/(2*a));
printf("虚部为%lf ",-(sqrt(-d))/(2*a));}}
}
int main(int argc, char* argv[])
{
double o,p,q;
scanf("%lf%lf%lf",&o,&p,&q);
root(o,p,q);
return 0;
}
程序的错是你的C等于比较写错了
if (a=0) 正确的是 if (a==0)
同样if(d=0)应该是
if (d==0)
另外,最后的一个else下面的内容要用{}括起来
一周热门 更多>