当前位置:网站首页>浙大版《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;
}
边栏推荐
- List and data frame of R language experiment III
- Which is more advantageous in short-term or long-term spot gold investment?
- 7-14 error ticket (PTA program design)
- Solutions to common problems in database development such as MySQL
- Overview of LNMP architecture and construction of related services
- "Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
- 《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
- C language file operation
- New version of postman flows [introductory teaching chapter 01 send request]
- Sentinel overall workflow
猜你喜欢
Hackmyvm target series (6) -videoclub
JDBC transactions, batch processing, and connection pooling (super detailed)
Based on authorized access, cross host, and permission allocation under sqlserver
Experiment 6 inheritance and polymorphism
Strengthen basic learning records
7-7 7003 combination lock (PTA program design)
Build domain environment (win)
Intranet information collection of Intranet penetration (5)
JVM memory model concept
WEB漏洞-文件操作之文件包含漏洞
随机推荐
Attack and defense world misc practice area (simplerar, base64stego, no matter how high your Kung Fu is, you are afraid of kitchen knives)
[MySQL table structure and integrity constraint modification (Alter)]
Intranet information collection of Intranet penetration (4)
Feature extraction and detection 14 plane object recognition
Which is more advantageous in short-term or long-term spot gold investment?
《英特尔 oneAPI—打开异构新纪元》
Intranet information collection of Intranet penetration (I)
Build domain environment (win)
Network technology related topics
Attack and defense world misc practice area (GIF lift table ext3)
Attach the simplified sample database to the SQLSERVER database instance
XSS unexpected event
图书管理系统
Data mining - a discussion on sample imbalance in classification problems
Strengthen basic learning records
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
7-6 local minimum of matrix (PTA program design)
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
Experiment five categories and objects
Constants, variables, and operators of SystemVerilog usage