编写程序,要求输入x和eps(设定的精度),按上述公式计算sinx的近似值,当最后一项小于eps时停止计算。
#include <stdio.h>
#include <math.h>
int main()
{
int x,n=1;
double eps,ans,term;
printf("input x,eps\n");
scanf("%d%lf",&x,&eps);
term = x,ans = x;
do{
term=-term*x*x/((n+1)*(n+2));
n+=2;
ans+=term;
}while(fabs(term)>=eps);
printf("sinx近似于%lf\n",ans);
return 0;
}