当前位置:网站首页>斐波那契数列
斐波那契数列
2022-04-21 12:41:00 【杨雄xiong.yang】
目录
一、题目描述
古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问第N个月的兔子总数为多少?
二、分析
这个题目看起来很复杂,但是当它前几个月
兔子对数个数列举出来:1 1 2 3 5 8 13 …,我们就能发现从三个月开始,兔子对数等于前两个月兔子对数的总和。
三、代码实现
#include <stdio.h>
int main()
{
int n = 0;
int i = 0;
int x = 1; //上上个月的兔子对数
int y = 1; //上一个月的兔子对数
int z = 1; //当前月的兔子对数
printf("请输入N\n");
scanf("%d", &n);
for(i = 3; i <= n; i++)
{
z = x + y;
x = y;
y = z; //更新前一个月和前两个月的兔子对数
}
printf("第%d个月时兔子总数为%d\n", n, z * 2);
return 0;
}
四、运行结果
版权声明
本文为[杨雄xiong.yang]所创,转载请带上原文链接,感谢
https://blog.csdn.net/xiongIT/article/details/124285649
边栏推荐
- CVPR 2022 oral | Hong Kong Chinese open source posec3d: skeleton motion recognition framework based on 3d-cnn
- 构建QML应用程序
- Russian Foreign Ministry official: the special military operation in Ukraine will end after the security threat caused by NATO is eliminated
- Laugh to death! The programmer's life extension guide is open source
- Title record of TIANTI competition (II)
- I think you can tear the linked list by hand (1)
- China Resources Yibao is rumored to have an IPO, and nongnongshanquan may usher in an early "old enemy"
- 2022年监理工程师考试质量、投资、进度控制练习题及答案
- Live broadcast of changes in the Jianghu: Li Jiaqi is trapped in a luxury house, Luo Yonghao fades out, and Weiya Sydney helps broadcast it
- mysql数据库操作语句练习
猜你喜欢

A comprehensive understanding of static code analysis

Berkeley, Samsung | a fast post training converter pruning framework

Office Word 2016 中Word自带公式编辑器编辑的公式转Mathtype出现omml2mml.xsl 问题的解决方法

2022年监理工程师考试基本理论与相关法规练习题及答案

IPEmotion采集J1939协议信号

Kubernetes service discovery monitoring apiserver

终于有人讲明白了!原来这才是全球低时延一张网技术

研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台

Live broadcast of changes in the Jianghu: Li Jiaqi is trapped in a luxury house, Luo Yonghao fades out, and Weiya Sydney helps broadcast it

Vggnet neural network based on pytorch for flower recognition
随机推荐
Notepad + + how to copy multiple lines and paste them to the corresponding position
爱可可AI前沿推介 (4.21)
字段行相同则合并在另外一个字段sql 语句?
走迷宫(BFS)
上个网课都能被AI分析“在走神”,英特尔这个情绪检测AI火了
赛事解析|乒乓球时序动作定位大赛亚军方案分享
风丘科技为您提供10M以太网解决方案
Who does the team listen to
Chris LATTNER, father of llvm: the golden age of compilers
Introduction notes to PHP zero Foundation (11): String
The persistence, abandonment and redemption of new consumer brands in the Shanghai epidemic
Vggnet neural network based on pytorch for flower recognition
2022年初级会计职称考试经济法基础练习题及答案
最长上升子序列(二)(贪心+二分)
弹性架构内容和成本探讨-数字化架构设计(3)
Detailed explanation of chrome developer tools I
阿里天池比赛——街景字符编码识别
One minute teaches you to use yolov5 to train your dataset and test it
nodejs 如何将 Buffer 数据转为 String
China Resources Yibao is rumored to have an IPO, and nongnongshanquan may usher in an early "old enemy"