当前位置:网站首页>簡單斐波那契
簡單斐波那契
2022-07-20 23:08:00 【Ding Jiaxiong】
題目
以下數列 0 1 1 2 3 5 8 13 21 … 被稱為斐波納契數列。
這個數列從第 3項開始,每一項都等於前兩項之和。
輸入一個整數 N,請你輸出這個序列的前 N項。
輸入格式
一個整數 N。
輸出格式
在一行中輸出斐波那契數列的前 N項,數字之間用空格隔開。
數據範圍
0<N<46
輸入樣例:
5
輸出樣例:
0 1 1 2 3
思路分析
題解
#include<iostream>
using namespace std;
int n;
int f[46];
int main(){
cin >> n;
f[1] = 0;
f[2] = 1;
for(int i = 3; i <= n;i ++){
f[i] = f[i - 1] + f[i - 2];
}
for(int i = 1;i <= n ; i++){
cout << f[i] << " ";
}
return 0;
}
边栏推荐
- C language file operation
- M matlab based IEEE802.15.4 home network efficient and energy-saving effective access method
- leetcode:952. Calculate the maximum component size by common factor
- MySQL的安装教程(嗷嗷详细,包教包会~)
- Communication project based on bio mode
- The introduction of 23 Filipino doctors for 18million was a hot topic, and the school teacher responded: expedient
- 产品加速推进、管理决策权提升,大众中国将以强劲复苏之势加速奔跑!
- 我创建了clickhouse引擎,但是创建SQL节点以后,显示已解绑?这种情况是怎么回事
- 西门子S7 模拟器使用教程
- 深入理解TCP協議
猜你喜欢
"Pilot Cup" is coming! Summon the strongest brain in scientific computing, 360000 prize pool waiting for you!
C language ----- array
Chinese style it operation and maintenance, out of its own "long-term" River
Digital transformation towards deep water: the banking industry continues to consolidate its scientific and technological foundation
【C】程序的实现
C language program environment and preprocessing
Emergency response > > types and disposal methods of network security emergency events
TIA botu_ Summary of difficulties related to the upgrade and migration of STEP7 version
UNIPRO multi terminal deployment to meet customers' diversified needs
Interview high concurrency, cool (full energy, collect quickly)
随机推荐
深入理解TCP协议的连接状态与可靠机制
Getting started with functions
趣店预制菜品牌战略发布会
本轮牛市下半场的行情走势分析?2021-04-07
SQL语句编写的练习(MySQL)
Makefile实现编译时间统计
Modbus Poll/Slave 模拟器使用教程
超越Transformer,清华、字节大幅刷新并行文本生成SoTA性能|ICML 2022
面试高并发,凉了(全程高能,赶快收藏)
1055 The World‘s Richest
leetcode:146. Least recently used cache by LRU
深入理解TCP协议
[激光器原理与应用-5]:激光二极管LD (Laser Diode)与激光二极管驱动器(LD驱动器)
【LeetCode每日一题——消失的数字】
M matlab performance simulation of optical fiber communication system based on Fiber Bragg grating sensor network connected to GPON, including decoding, unpacking, demultiplexing, rate recovery, frami
[go language] (I) environment building and understanding vscode tools
Mysql database and table building (I)
Emergency response > > basic skills and tools
如何实施企业内容管理(ECM)系统
Particle dissipation of unity 3D characters