#include
#include
#define P 3.1415927
double sinx(double x) {
double eps = 1E-8,delta = x;
double sgn = -1,sin = x,n = 1;
double nator = 1;
while(fabs(delta) > eps) {
nator *= (n + 1.0)*(n + 2.0);
delta *= x*x/nator;
sin += sgn*delta;
sgn = -sgn;
n += 2;
}
return sin;
}
double cosx(double x) {
double eps = 1E-8,delta = 1;
double sgn = -1,cos = 1,n = 1;
double nator = 1;
while(fabs(delta) > eps) {
nator *= n*(n + 1.0);
delta *= x*x/nator;
cos = cos + sgn*delta;
sgn = -sgn;
n += 2;
}
return cos;
}
int main() {
double alpha;
int T;
printf("测试次数:");
scanf("%d",&T);
while(T--) {
printf("请输入度数:");
scanf("%lf",&alpha);
alpha *= P/180;
printf("msin(%lf) = %lf\n",alpha,sinx(alpha));
printf("sin(%lf) = %lf\n",alpha,sin(alpha));//调用系统函数用于对比
printf("mcos(%lf) = %lf\n",alpha,cosx(alpha));
printf("cos(%lf) = %lf\n",alpha,cos(alpha));//调用系统函数用于对比
}
return 0;
}