错位相减法
如果差位为n次?
如何用程序解决(迭代)
#include<stdlib.h> #include<stdio.h> #include<math.h> int jiecheng(int n) { if(n<=1){return 1;} if(n>1){return n*jiecheng(n-1);} } int zuhe(int n,int m) { if(m>=n){return 1;} return jiecheng(n)/(jiecheng(m)*jiecheng(n-m)); } double rooten(double A,int n) { if(n==0) { double temp1; temp1=A/(A-1); return temp1; } if(n>0) { double temp=0; for(int i=1;i<n+1;i++) { temp +=zuhe(n,i)*rooten(A,n-i); printf("test-i%d\n",i); printf("test-ZUHE%f\n",zuhe(n,i)); } printf("test%f\n",temp/(A-1)); return temp/(A-1); } } void main() { double A; int n; printf("输入你的A(比的底,为一浮点数)"); scanf("%lf",&A);//scanf接受double类型的变量时,应为lf printf("输入你的n(差的幂,为一整数数)"); scanf("%d",&n); printf("你的A%f",A); printf("你的n%d",n); printf("你需要的结果%f",rooten(double(A),int(n))); //printf("验算结果%f",20/27.0); system("pause"); }//代码如上,输入即得结果。