首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

一个简单程序的异常所在!

2012-03-11 
一个简单程序的错误所在!!!!!!#includemath.h floatf(floatx){floatyy((x-5.0)*x+16.0)-80.0return(y

一个简单程序的错误所在!!!!!!
#include   "math.h "
float   f(float   x)
{
        float   y;
        y=((x-5.0)*x+16.0)-80.0;
        return(y);
}
float   xpoint(float   x1,float   x2)
{
        float   y;
        y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
        return(y);
}
float   root(float   x1,float   x2)
{
        float   x,y,y1;
        y1=f(x1);
        do
        {
                x=xpoint(x1,x2);
                y=f(x);
                if(y1*y> 0)
                {
                        y=y1;
                        x1=x;
                }
                else
                x2=x;
        }
        while(fabs(y)> 0.0001);
        return(x);
}
main()
{
        float   x,x1,x2,f1,f2;
        do
        {
                printf( "please   input   two   numbers\n ");
                scanf( "%f,%f ",&x1,&x2);
                printf( "x1=%f,x2=%f\n ",x1,x2);
                f1=f(x1);
                f2=f(x2);
        }
        while(f1*f2> =0);
        x=root(x1,x2);
        printf( "A   ROOT   OF   EPUATION   IS   %8.4f\n ",x);
}

[解决办法]
加一个#include "stdio.h "
将main()的声明改成int main()
可以编译通过
[解决办法]
“编译通过,就是有逻辑错误”,有没有试过自己单步跟踪一下看看,先查清是到哪一步出的问题。
[解决办法]
逻辑错误只能你自己搞定了 ...

float f(float x)

都不知道这是干吗的,
没法调试 ...

楼主你自己断点+单步调试吧

热点排行