#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{ double cf(double x,int i);
int jc(int i);
double x,a1,sum=0,num=1;
int sign=-1,i,a2;
scanf("%lf",&x);
//输入数值在1.2以下才能正常
for(i=1;fabs(num)>1e-8;i+=2)
{sign=sign*(-1);
a1=cf(x,i);
a2=jc(i);
num=sign*a1/a2;
sum=sum+num;
}
printf("%.8f\n",sum);
getch();
return 0;
}
double cf(double x,int i)
{ int j;
double y;
for(j=1,y=1;j<=i;j++)
{y=y*x;
}
return y;
}
int jc(int i)
{int j,sum=1;
for(j=1;j<=i;j++)
{sum=sum*j;
}
return sum;
}
不知道哪错了
[此贴子已经被作者于2015-12-7 20:22编辑过]