当前位置:网站首页>Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
2022-07-06 14:42:00 【No two or three things】
experiment 4-1-10 The problem of rabbit reproduction
fraction 15
Full screen browsing topics
Switch layout
author Xu Jingchun
Company Zhejiang University
A couple of Rabbits , From the day after birth 3 A couple of rabbits are born every month from . The little rabbit grows to the third place 3 Two months later, a couple of rabbits were born every month . If the rabbits don't die , May I ask 1 A pair of rabbits born six months ago , It will take at least a few months for the total number of rabbits to reach N Yes ?
Input format :
The input gives no more than 10000 The positive integer N.
Output format :
Output the total number of rabbits in one line to N Minimum number of months required .
sample input :
30
sample output :
9
Code length limit
16 KB
The time limit
400 ms
Memory limit
64 MB
Code implementation :
# include <stdio.h>
main() {
int N;
scanf("%d",&N);// 1,1,2,3 Satisfy Fibonacci sequence
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;
}
边栏推荐
- MySQL learning notes (stage 1)
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
- Flash implements forced login
- [pointer] find the length of the string
- The most popular colloquial system explains the base of numbers
- 指针--剔除字符串中的所有数字
- Get started with Matplotlib drawing
- 【指针】八进制转换为十进制
- “人生若只如初见”——RISC-V
- Using flask_ Whooshalchemyplus Jieba realizes global search of flask
猜你喜欢
Realize applet payment function with applet cloud development (including source code)
Constants, variables, and operators of SystemVerilog usage
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
关于交换a和b的值的四种方法
数据库多表链接的查询方式
Data mining - a discussion on sample imbalance in classification problems
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Windows platform mongodb database installation
随机推荐
Function: string storage in reverse order
Wu Enda's latest interview! Data centric reasons
Constants, variables, and operators of SystemVerilog usage
函数:求方程的根
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
“Hello IC World”
Circular queue (C language)
Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)
Lintcode logo queries the two nearest saplings
《统计学》第八版贾俊平第二章课后习题及答案总结
Uibutton status exploration and customization
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
What is the transaction of MySQL? What is dirty reading and what is unreal reading? Not repeatable?
1. Payment system
Sword finger offer 23 - print binary tree from top to bottom
Network technology related topics
Mathematical modeling idea of 2022 central China Cup
Feature extraction and detection 14 plane object recognition
Solutions to common problems in database development such as MySQL
【指针】数组逆序重新存放后并输出