| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 370 人关注过本帖
标题:用弦截法求方程的近似根(麻烦谁给看一下错误在哪)
只看楼主 加入收藏
wang6969772
Rank: 2
来 自:陕西西安
等 级:论坛游民
帖 子:11
专家分:10
注 册:2014-10-26
结帖率:25%
收藏
 问题点数:0 回复次数:0 
用弦截法求方程的近似根(麻烦谁给看一下错误在哪)
#include<stdio.h>
#include<math.h>
float f(float x)           /*定义f函数,以实现f(x)=x^3-5*x^2+16*x-80*/
{
    float y;
    y=((x-0.5)*x+16.0)*x-80.0;
    return(y);
}
float xpoint(float x1,float x2)      /*定义xpoint函数,求出弦与x轴的交点*/
{
    float y;
    y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
    return(y);
}
float root(float x1,float x2)    /*定义root函数,求近似根*/
{
    float x,y,y1;
    y1=f(x1);
    do
    {
        x=xpoint(x1,x2);
        y=f(x);
        if(y*y1>0)      /*f(x)与f(x1)同符号*/
        {
            y1=y;
            x1=x;
        }
        else
            x2=x;
        while(fabs(y)>=0.0001);
        return(x);

}
    void main()        /*主函数*/
    {
        float x1,x2,f1,f2,x;
        do
        {
            printf("input x1,x2:\n");
            scanf("%f,%f",&x1,&x2);
            f1=f(x1);
            f2=f(x2);

        }
        while(f1*f2>=0);
            x=root(x1,x2);
        printf("a root of equation is %8.4f\n",x);
    }
搜索更多相关主题的帖子: include return 
2014-11-18 22:12
快速回复:用弦截法求方程的近似根(麻烦谁给看一下错误在哪)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017653 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved