C语言求1元2次方程时的问题,很感谢能回答我的人我的程序步骤;#include#includevoid main(){float a,b,c,disc,x1,x2,p;printf("Please input the a b c:");scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc = b*b-4*a*c;if (disc < 0);printf("It is a

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/08 20:48:07

C语言求1元2次方程时的问题,很感谢能回答我的人我的程序步骤;#include#includevoid main(){float a,b,c,disc,x1,x2,p;printf("Please input the a b c:");scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc = b*b-4*a*c;if (disc < 0);printf("It is a
C语言求1元2次方程时的问题,很感谢能回答我的人
我的程序步骤;
#include
#include
void main()
{
float a,b,c,disc,x1,x2,p;
printf("Please input the a b c:");
scanf("a=%f,b=%f,c=%f",&a,&b,&c);
disc = b*b-4*a*c;
if (disc < 0);
printf("It is a error!");
else
p = -b/(2*a);
x1 = p + sqrt(disc)/(2*a);
x2 = p - sqrt(disc)/(2*a);
printf("x1=%5.2f,x2=%5.2f",x1,x2);
}
最后调试有1处错误:
C:\Documents and Settings\user\桌面\编程软件\Cpp1.c(11) :error C2181:illegal else without matching if
C:\Documents and Settings\user\桌面\编程软件\Cpp1.c(13) :warning C4244:'=' :conversion from 'double ' to 'float ',possible loss of data
C:\Documents and Settings\user\桌面\编程软件\Cpp1.c(14) :warning C4244:'=' :conversion from 'double ' to 'float ',possible loss of data
执行 cl.exe 时出错.

C语言求1元2次方程时的问题,很感谢能回答我的人我的程序步骤;#include#includevoid main(){float a,b,c,disc,x1,x2,p;printf("Please input the a b c:");scanf("a=%f,b=%f,c=%f",&a,&b,&c);disc = b*b-4*a*c;if (disc < 0);printf("It is a
很容易改
1,把if行后面的分号去掉,if 语句完整表述之前不需要分号;
2,把定义时的“float"改成“double”,(若用float定义的话,后面开方运算默认的是数据是double型,强制转换可能出现数据丢失.)
p.s.一下,“it is an error”