请各位达人帮我找找问题出在哪儿

来源:百度知道 编辑:UC知道 时间:2024/07/06 22:30:41
判断方程解的

#include "Stdio.h"
#include "Conio.h"
#include "Math.h"

int main(void)
{
int a,b,c,x;
printf("ax^2+bx+c=0\n");
printf("Please input a,b,c:");
scanf("%d,%d,%d",&a,&b,&c);
x=b*b-4*a*c;
if (x<0)
{
printf("ZERO");
goto end;
}
if (x==0)
{
printf("ONE");
printf("x=%f",(float)(-b/(2*a)));
goto end;
}
(float)x=sqrt(x);
printf("x1=%f",(float)((-b+x)/(2*a)));
printf("x2=%f",(float)((-b-x)/(2*a)));
end:
getch();
return 0;
}

提示:错误 03-3.c 23: 需要逻辑0或非0在 main 函数中
(float)x=sqrt(x);
这一行

多谢

数值类型的问题
x是int,求出来的是float

(float)x=sqrt(x); 因为x已经是int型了,无法将float型赋值给它

可以改成
#include "stdio.h"
#include "conio.h"
#include "math.h"

int main(void)
{
int a,b,c,x;
float y;
printf("ax^2+bx+c=0\n");
printf("Please input a,b,c:");
scanf("%d,%d,%d",&a,&b,&c);
x=b*b-4*a*c;
if (x<0)
{
printf("ZERO");
goto end;
}
if (x==0)
{
printf("ONE");
printf("x=%f",(float)(-b/(2*a)));
goto end;
}
y=sqrt(x);
printf("x1=%f",(float)((-b+y)/(2*a)));
printf("x2=%f",(float)((-b-y)/(2*a)));
end:
getch();
return 0;
}

不深究算法的问题的话,问题出在这里:
赋值表达式想要有意义,有一个左式和右式的概念,
右式可以是一个表达式,而左式就不能是一个表达式,只能是一个值.
而(float)x则是一个强制转换操作,不是一个数值,
将一个表达式赋给一个表达式,这是会出错的

算法也有问题,输入1 2 1 和1 -3 2 都给出ZERO<