题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
http://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
#include <stdio.h>
#include <string.h>
//斐波那契递归
int f(int n);
int main()
{
int n;
while ((scanf("%d", &n)) != EOF)
printf("%d\n", f(n));
return 0;
}
int f(int n)
{
int ret=0;
if (n == 1)
ret = 1;
else if (n == 2)
ret = 1;
else if (n == 3)
ret = 2;
else{
ret=f(n-1)+f(n-2);
}
return ret;
}