循环-05. 兔子繁衍问题

 1 /*
 2  * Main.c
 3  * C5-循环-05. 兔子繁衍问题
 4  * 采用斐波那契数列算法
 5  *  Created on: 2014年7月25日
 6  *      Author: Boomkeeper
 7  *******测试通过**********
 8  */
 9 
10 #include <stdio.h>
11 
12 int cal(int m){
13     if(m<=2)
14         return 1;
15     else
16         return (cal(m-1)+cal(m-2));
17 }
18 int main(){
19     int amount;//兔子要达到的总对数
20     int month=1;//月数
21 
22     scanf("%i",&amount);
23     while(cal(month)<amount)
24         month++;
25     printf("%i\n",month);//第month个月兔子对数达到amount
26 
27     return 0;
28 }

参考:

http://sakyone.iteye.com/blog/365325

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-05

posted @ 2014-07-25 18:37  Boomkeeper  Views(928)  Comments(1Edit  收藏  举报
最好的流量统计 网站流量计数器