当前位置:网站首页>浙大版《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;
}
边栏推荐
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- Lintcode logo queries the two nearest saplings
- Detailed explanation of network foundation
- Record an API interface SQL injection practice
- [issue 18] share a Netease go experience
- 浅谈漏洞发现思路
- captcha-killer验证码识别插件
- [three paradigms of database] you can understand it at a glance
- The most popular colloquial system explains the base of numbers
- 《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
猜你喜欢

Callback function ----------- callback

Wei Shen of Peking University revealed the current situation: his class is not very good, and there are only 5 or 6 middle-term students left after leaving class

Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence

网络基础之路由详解

JDBC看这篇就够了

Record once, modify password logic vulnerability actual combat

《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案

Hackmyvm target series (2) -warrior

内网渗透之内网信息收集(一)

Data mining - a discussion on sample imbalance in classification problems
随机推荐
C language file operation
7-8 7104 Joseph problem (PTA program design)
Detailed explanation of three ways of HTTP caching
Intel oneapi - opening a new era of heterogeneity
Strengthen basic learning records
HackMyvm靶机系列(5)-warez
HackMyvm靶机系列(7)-Tron
Detailed explanation of network foundation
网络层—简单的arp断网
Intranet information collection of Intranet penetration (4)
SystemVerilog discusses loop loop structure and built-in loop variable I
New version of postman flows [introductory teaching chapter 01 send request]
The most popular colloquial system explains the base of numbers
Hackmyvm target series (7) -tron
Middleware vulnerability recurrence Apache
[experiment index of educator database]
Web vulnerability - File Inclusion Vulnerability of file operation
Experiment five categories and objects
Hackmyvm target series (2) -warrior
记一次,修改密码逻辑漏洞实战