当前位置:网站首页>浙大版《C语言程序设计实验与习题指导(第3版)》题目集
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
2022-07-06 09:23:00 【无二三事】
实验4-1-10 兔子繁衍问题
分数 15
全屏浏览题目
切换布局
作者 徐镜春
单位 浙江大学
一对兔子,从出生后第3个月起每个月都生一对兔子。小兔子长到第3个月后每个月又生一对兔子。假如兔子都不死,请问第1个月出生的一对兔子,至少需要繁衍到第几个月时兔子总数才可以达到N对?
输入格式:
输入在一行中给出一个不超过10000的正整数N。
输出格式:
在一行中输出兔子总数达到N最少需要的月数。
输入样例:
30
输出样例:
9
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
代码实现:
# include <stdio.h>
main() {
int N;
scanf("%d",&N);// 1,1,2,3满足斐波那契数列
int a = 1,b = 1,max = 1,temp,month = 1;
if (N == 1) {
printf("%d",month);
}else {
month = 2;
while(max < N) {
temp = a;
a += b;
b = temp;
max = (a >= b) ? a : b;
month += 1;
}
printf("%d",month);
}
return 0;
}
边栏推荐
- Xray and Burp linked Mining
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- JDBC看这篇就够了
- How to understand the difference between technical thinking and business thinking in Bi?
- Intranet information collection of Intranet penetration (I)
- 网络基础之路由详解
- Package bedding of components
- A complete collection of papers on text recognition
- Applet Web Capture -fiddler
- What language should I learn from zero foundation. Suggestions
猜你喜欢

Harmonyos JS demo application development

攻防世界MISC练习区(gif 掀桌子 ext3 )

网络基础详解

xray与burp联动 挖掘

浅谈漏洞发现思路

《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案

Build domain environment (win)

Data mining - a discussion on sample imbalance in classification problems

Applet Web Capture -fiddler

Solutions to common problems in database development such as MySQL
随机推荐
What language should I learn from zero foundation. Suggestions
[issue 18] share a Netease go experience
[MySQL database learning]
循环队列(C语言)
Realize applet payment function with applet cloud development (including source code)
外网打点(信息收集)
The most popular colloquial system explains the base of numbers
The difference between layer 3 switch and router
Experiment 7 use of common classes (correction post)
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
《英特尔 oneAPI—打开异构新纪元》
Intel oneapi - opening a new era of heterogeneity
Detailed explanation of three ways of HTTP caching
[VMware abnormal problems] problem analysis & Solutions
[err] 1055 - expression 1 of order by clause is not in group by clause MySQL
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
Which is more advantageous in short-term or long-term spot gold investment?
[experiment index of educator database]
小程序web抓包-fiddler