# include <stdio.h>
# include<math.h>
float px(float x,int n)
{
/* float term=1.0;
float sum=0,sign=-1.0;
while(n)
{ sign*=-1;
term=term*x*sign;
n--;
sum=sum+term;
}这里是我自己写的非递归算法,验证用*/
float sum=0;
if(n=1)
return x;
else
return x*(1-px(x,n-1));
}
int main()
{
int n=4;
float x=3.0,sum=0;
sum=px(x,n);
printf("%f",sum);
return 0;
}