码迷,mamicode.com
首页 > 其他好文 > 详细

循环-05. 兔子繁衍问题

时间:2014-07-26 01:04:56      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   strong   io   2014   re   

 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

循环-05. 兔子繁衍问题,布布扣,bubuko.com

循环-05. 兔子繁衍问题

标签:style   blog   http   color   strong   io   2014   re   

原文地址:http://www.cnblogs.com/boomkeeper/p/C5.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!