该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#define PI 3.1415927
double FACT(double x);
double fact(int n);
int main()
{
int n,i,k,flag;
double x,sin,temp,index;
while(scanf("%lf%d",&x,&n)!=EOF)
{
FACT(x);
flag=1; index=0.1; temp=x; sin=0;/*初始化数据*/
for(i=1;i
index*=index; /*计算出10的-n次方*/
i=1;
while(fabs(temp)>=index) /*判断循环条件*/
{
temp=flag*x/fact(i); /*先计算x/i!*/
for(k=0;k
temp*=x;
sin+=temp; /*加到sin*/
flag=-flag; /*符号变换*/
i+=2;
}
printf("%.*f\n",n,sin); /*输出*/
}
return 0;
}
double fact (int n) /*调用阶乘函数*/
{
double result;
if(n==1||n==0)
result=1;
else
result=n*fact(n-1);
return result;
}
double FACT(double x)
{
while(x>PI/2||x
x-=2*PI;
return x;
}