兔子问题

来源:互联网 发布:校园网络搭建毕业论文 编辑:程序博客网 时间:2024/04/29 00:59

//Fibonacci’s problem兔子问题//A certain man put a pair of rabbits in a place surrounded on all sides by a wall.How many pairs of rabbits can be produced from that pair in a year if it is        //supposed that every month each pair begets a new pair which from the second month on becomes productive?//圈养1只可生殖的兔子,小兔子过1个月才可以生殖。一年后有多少只兔子呢?//每个月的兔子总数都是前一个月加上新生的兔子。f(n)=f(n-1)+x。那么x是多少呢?//假设我们已经知道现在有f(n)个兔子。即2个月后f(n)个兔子肯定都可以生小兔子。即知道了2个月后心增加的x为f(n)。        //所以有:/*     f(n+2)=f(n+1)+f(n);
  #include<stdio.h>int fibonacci(int n){if(n=1|n=0) return 1;else return fibonacci(n-1);}        int main (){int n=12;int sum;sum=fibonacci(12);printf("there arr total d%\n",sun);}
原创粉丝点击