#include <stdio.h>
#include <math.h>
#define
PI
3.14159
double x_power(double x, double y);//求x的y次幂
int factor(int i); //求i的阶乘
int main()
{
int count = 1;//带有x的 第几项
double x, temp;
double sum = 1.0;//
int t_f = factor(count*2);
double o_xp;
printf("输入x的值(度):");
scanf("%lf", &x);
x = x/180.0;
x = x*PI;
o_xp = x_power( x, count*2 );
sum += (pow(-1, count)*o_xp) / t_f;
temp = o_xp / t_f;
while( temp >= 0.0000001 )
{
++count;
t_f = factor(count*2);
o_xp = x_power( x, count*2 );
sum += (pow(-1, count)*o_xp) / t_f;
temp = o_xp / t_f;
}
printf("%f\n", sum);
return 0;
}
double x_power(double x , double i)
{
return pow(x, i);
}
int factor( int i )
{
if( i == 1 )
return 1;
else
return i*factor(i-1);
}