当前位置:网站首页>Zzuli:1055 rabbit reproduction
Zzuli:1055 rabbit reproduction
2022-07-03 14:34:00 【Snake_____】
Title Description
This is an interesting classical mathematical problem , Famous Italian mathematician Fibonacci A question was raised : There's 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 . According to this rule , Suppose no rabbits died , In the first month, there was a couple of newborn rabbits , Ask No n How many pairs of rabbits in a month ?
Input
Enter the number of months n(1<=n<=44).
Output
Output No n How many pairs of rabbits in a month .
The sample input Copy
3
Sample output Copy
2
Tips
This topic is a classic introduction to recursion : use f(n) It means the first one n Number of rabbits in months , be : f(n) = f(n-1) + Number of rabbits born this month and , Number of rabbits born this month = f(n-2) ( Because every rabbit that existed last month , A new rabbit will be born this month ) therefore ,f(n) = f(n-1) + f(n-2) That's the famous one fabinacci The sequence , The latter is equal to the sum of the first two : 1 1 2 3 5 8.....
#include <stdio.h>
int main()
{
int i,n,a=1,b=1,c;
scanf("%d",&n);
if(n==1)
{
printf("%d",a);
}
else
{
for(i=2;i<n;i++)
{
c=a;
a=a+b;
b=c;
}
printf("%d",a);
}
return 0;
}
边栏推荐
- Zhejiang University Edition "C language programming (4th Edition)" topic set reference ideas set
- Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
- [qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
- Find the sum of the elements of each row of the matrix
- Mysql多表查询 #子查询
- 7-16 find the set of integers that meet the given conditions
- Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
- 使用并行可微模拟加速策略学习
- 泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
- Sword finger offer 28 Symmetric binary tree
猜你喜欢
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
adc128s022 ADC verilog设计实现
Four data flows and cases of grpc
Understanding of closures
Showmebug entered Tencent conference, opening the era of professional technical interview
puzzle(016.4)多米诺效应
Puzzle (016.4) domino effect
分布式事务(Seata) 四大模式详解
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
Jiuyi cloud black free encryption free version source code
随机推荐
提高效率 Or 增加成本,开发人员应如何理解结对编程?
Address book sorting
Time conversion ()
一文了解微分段应用场景与实现机制
Output student grades
7-24 reduction of the simplest fraction (rolling Division)
7-18 finding the single root of polynomial by dichotomy
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
Zabbix添加Calculated items后保存页面成空白
7-20 print 99 formula table (format output)
Common shortcut keys in PCB
Tonybot humanoid robot infrared remote control play 0630
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
Zzuli:1041 sum of sequence 2
洛谷P5194 [USACO05DEC]Scales S 题解
adc128s022 ADC verilog设计实现
Sendmail无法发送邮件及发送过慢解决
数学常数表 by q779