正在加载图片...
#include<stdio. h 切忌: 将递归函数的内容写至主函数中; 将通归中的语句放至循环中 在递归函数中写s(x,n)=S(x,n-1)+pow(x,n) wnn Please puT s s=S(, n) scam(“%f,‰,&8prm("ns(%f,%)=%fw”,x,n,s) s=S(x, n: prnf(nS(%f%d)=% double s( double x,intn)用递推求解 [double sum=0; int i double s( double x,, int for(=-1<=n++)递推要用循环语句实现吻/ if(n=:1) return x sum+=pow(,i) return sum else return S(x, n-1)+pow(x, n) 递归要通过函数的依次调用实现*4 #include<stdio.h> #include<math.h> double S(float x, int n); void main() { double x,s; int n; printf(“please input x,n:\n”); scanf(“%lf,%d”,&x,&n); s=S(x,n); printf(“\nS(%lf,%d)=%lf\n”,x,n,s); } double S(double x, int n) {if(n==1) return x; else return S(x,n-1)+pow(x,n); /*递归要通过函数的依次调用实现*/ } 习题5.12程序 #include<stdio.h> #include<math.h> double S(float x, int n); void main() { double x,s; int n; printf(“please input x,n:\n”); scanf(“%lf,%d”,&x,&n); s=S(x,n); printf(“\nS(%lf,%d)=%lf\n”,x,n,s); } double S(double x, int n)/*用递推求解*/ {double sum=0; int i; for(i=1;i<=n;i++)/*递推要用循环语句实现*/ sum+=pow(x,i); return sum; } 切忌: 将递归函数的内容写至主函数中; 将递归中的语句放至循环中; 在递归函数中写s(x,n)=S(x,n-1)+pow(x,n);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有