1 #include "stdio.h" 2 #include "iostream" 3 4 int Fibonacci(int n) 5 { 6 int t1, t2; 7 if (n == 1 || n == 2) 8 { 9 return 1; 10 } 11 else 12 { 13 t1 = Fibonacci(n-1); 14 t2 = Fibonacci(n-2); 15 return t1 + t2; 16 } 17 } 18 19 int main() 20 { 21 int n, num; 22 23 scanf("%d",&n); 24 num = Fibonacci(n); 25 printf("经过 %d 月的时间, 共能繁殖成 %d 对兔子!\n",n,num); 26 system("pause"); 27 return 0; 28 }
注意思想:
第一个月:1对
第二个月:1对
第三个月:2对
第三个月:3对
第四个月:5对
。。。
从第三个月开始,每个月的兔子总对数等于前两个月兔子对数的总和。
原文链接: https://www.cnblogs.com/zhibei/p/11145763.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/298376
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!