#include
#include
double fun(double x,int n)
{
int i;
int j;
double faci=1.0;
double s=1.0;
for(i=1;i<=n;i++)
{
faci=1.0;
if(i>0)
{
for(j=1;j<=i;j++)
{
faci*=j;
}
}
s+=pow(x,i)/faci;
}
return s;
}
int main()
{
double x;
int n;
scanf("%lf%d",&x,&n);
printf("%lf\n",fun(x,n));
}
0.3 10
1.349859
请按任意键继续. . .
#include
double fun(double x,int n)
{double sum=1.0,a=1.0;
int i,j=1;
for(i=1;i<=n;i++)
{a*=x;
j*=i;
sum=sum+a/j;
}
return sum;
}
int main()
{
double x;
int n;
scanf("%lf%d",&x,&n);
printf("%lf\n",fun(x,n));
}
自己看一下,我刚才编译了的,能够实现该功能,希望你满意