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对

。。。

从第三个月开始,每个月的兔子总对数等于前两个月兔子对数的总和。

相关文章:

  • 2022-03-07
  • 2022-12-23
  • 2021-09-29
  • 2022-02-20
  • 2021-12-07
  • 2021-11-25
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-06
  • 2022-03-11
  • 2021-12-20
  • 2022-02-26
  • 2022-12-23
相关资源
相似解决方案