c语言程序疑问

来源:百度知道 编辑:UC知道 时间:2024/05/25 18:25:25
#include<stdio.h>
#include<math.h>
float getvaluat(float x)
{
return x*x*x-x*x-4*x-7;
}
void main()
{
float a=3,b=4,c;
c=(a+b)/2;
while(fabs(getvalue(c))>0.001 && fabs(a-b)>0.001)
{
if(getvalue(c)*getvalue(b)<0) a=c;
if(getvalue(c)*getvalue(a)<0 )b=c;
c=(a+b)/2;
}
printf("%0.3f\n",c);
}
怎么不能执行呢?

细心点,第三行float getvaluat(float x)
拼写错误。getvalue!!

#include<stdio.h>
#include<math.h>
float getvalue(float x)
{
return x*x*x-x*x-4*x-7;
}
void main()
{
float a=3,b=4,c;
c=(a+b)/2;
while(fabs(getvalue(c))>0.001 && fabs(a-b)>0.001)
{
if(getvalue(c)*getvalue(b)<0) a=c;
if(getvalue(c)*getvalue(a)<0 )b=c;
c=(a+b)/2;
}
printf("%0.3f\n",c);
}
函数头 和下面 调用处不一致!
上面是getvaluat 下面是 getvalue

1,同意一楼;
2,printf("%.3f\n",c);就可以了别0.3
因为它表示,占0个长度,虽然系统会自动调整好然后正确输出,
但是以后要注意了。

函数名不一致!
把getvaluat改为getvalue,就行了!

#include<stdio.h>
#include<math.h>

float getvalue(float x)
{
return x*x*x-x*x-4*x-7;
}

void main()
{
float a=3,b=4,c;
c=(a+b)/2;
while(fabs(getvalue(c))>0.001 && fabs(a-b)>0.001)
{
if(getvalue(c)*getvalue