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; }