#include
#include
#include
unsigned int jiecheng(unsigned x){
if(x==1){
return 1;
}else{
return x * jiecheng(x-1);
}
}
double fuc(double x ,unsigned int n){
unsigned int i;
float result = 1.0;
if(n==0){
return 1.0;
}
else{
for(i=1;i<=n;i++){
result += pow(-1,i+1)*pow(x,i)/jiecheng(i);
}
return result;
}
}
void main()
{
printf("%lf \n",fuc(1,0));
printf("%lf \n",fuc(1,1));
printf("%lf \n",fuc(2,10));
system("pause");
}
应该没有问题,while循环跟for循环没有区别的,自己改吧