确定精度下求sinx

确定精度下求sinx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include <math.h>
int main()
{
double eps,x;
scanf("%lf%lf",&x,&eps);
double num=x,sum=x;
for(int n=1;fabs(num)>=eps;n++)
{
num*=-1*x*x/((2*n)*(2*n+1));
sum+=num;
}
printf("sinx=%lf",sum);
return 0;
}