C语言求1元2次方程时的问题,很感谢能回答我的人
我的程序步骤;#include<stdio.h>#include<math.h>voidmain(){floata,b,c,disc,x1,x2,p;printf("Pl...
我的程序步骤;
#include<stdio.h>
#include<math.h>
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 时出错. 展开
#include<stdio.h>
#include<math.h>
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 时出错. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询