用递归解决经典的“鸭子”问题
#include"stdio.h"
#include"math.h"
int f(int n){
if(n==8)
return 2;
else
return (f(n+1)+1)*2;
}
int t(int m){
int f(int n);
if(m==8)
return 2;
else
return f(m)/2+1;
}
int main(){
printf("鸭子的总数为:%dt",f(1));
printf("经过各个村庄所卖的鸭子数为:%d %d %d %d %d %d %d t",t(1),t(2),t(3),t(4),t(5),t(6),t(7));
return 0;
}
最后
以上就是笑点低苗条最近收集整理的关于用递归解决实际问题的全部内容,更多相关用递归解决实际问题内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复