#include <stdio.h>
#include <math.h>
double fun(double x)
{
double s1=1.0,s0=0.0;
double t=1.0;
int n=1;
do
{
s0=s1;//此时s0为s1的上一项
t=t*(0.5-n+1)*x/n;
s1=s1+t;
n++;
}
while(fabs(s1-s0)>=1e-6);//fab求绝对值 1e-6表示10的-6次方
return s1;
}
void main()
{
double x,s;
printf("输入x:");
scanf("%lf",&x);
s=fun(x);
printf("s=%f\n",s);
}