15.求函数:sin(x)=x/1! - x3/3! + x5/5! -x7/7! +…,最后一项精度不低于0.000001

#include <iostream>
using namespace std;
 
int main() 
{ 
    double x,sinx=0.0,jbf,j=1.0; 
    cin>>x; 
    jbf=x; 
    int k=1,l=1; 
    double n=1; 
    while(j>=1e-6) 
    { 
        j=jbf/n; 
        sinx=sinx+k*j; 
        jbf=jbf*x*x; 
        k=-k; 
        n=n*(l+1)*(l+2); 
        l+=2; 
    } 

    cout<<"sin(x) = "<<sinx<<endl; 
    return 0;
}

 

posted on 2014-08-05 21:07  Ji_xiaowu  阅读(918)  评论(0编辑  收藏  举报

导航