题目:

结果:

代码:
用递归,出口为n==1时
#include <stdio.h>
#include<stdlib.h>
int countPeach(int n);
int main()
{
int n;
scanf("%d",&n);
printf("%d",countPeach(n));
return 0;
}
int countPeach(int n)
{
if(n==1)
return 1;
else
return 2*(1+countPeach(n-1));
}
yysy,感觉这个题用递归处理真舒服~嘻嘻
文章介绍了如何使用递归函数`countPeach`计算整数n的某个特性,当n等于1时返回1,否则返回2乘以(n-1)的结果。作者提到此题用递归处理很直观。

被折叠的 条评论
为什么被折叠?



