码迷,mamicode.com
首页 > 其他好文 > 详细

jichu

时间:2018-11-23 23:29:22      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:return   多项式   abs   span   pre   sum   while   输出   bsp   

76 题 请编写函数 fun,其功能时:计算并输出当 x<0.97 时下列多项式的值,直到|
sn-s(n-1)|<0.000001 为止。
Sn=1+0.5x+0.5(0.5-1)/2!x(2)+…+0.5(0.5-1)(0.5-2)…..(0.5-n+1)/n!x(n)


double f(double x)
{
    double sum=0.0,t=1.0,p=1.0;
    double s1=1.0,s0=0.0;
    int n =1;
    do{
        s0=s1;
        sum+=s0;
        t*=n;
        p*=(0.5-n+1)*x;
        s1=p/t;
        n++;
    }while(fabs(s1-s0)>=1e-6);
    return  sum;
}

 

jichu

标签:return   多项式   abs   span   pre   sum   while   输出   bsp   

原文地址:https://www.cnblogs.com/tingtin/p/10010092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!