当前位置:网站首页>简单斐波那契
简单斐波那契
2022-07-19 22:13: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;
}
边栏推荐
- MySQL的安装教程(嗷嗷详细,包教包会~)
- D static import object
- m基于matlab的IEEE802.15.4家庭网络高效节能的有效接入方法
- SQL语句编写的练习(MySQL)
- Makefile implements compilation time statistics
- IEC104 模拟器使用教程
- My notepad++ plug-in recommendation
- 面试高并发,凉了(全程高能,赶快收藏)
- 佣金最低的证券交易所是哪家?网上客户经理开户安全吗
- [go language] (I) environment building and understanding vscode tools
猜你喜欢
MySQL的安装教程(嗷嗷详细,包教包会~)
【C】 Program implementation
leetcode:632. Minimum interval
[go language] (I) environment building and understanding vscode tools
C language ----- array
[激光器原理与应用-5]:激光二极管LD (Laser Diode)与激光二极管驱动器(LD驱动器)
Particle dissipation of unity 3D characters
TIA botu_ Summary of difficulties related to the upgrade and migration of STEP7 version
多线程进阶篇Step2
Matrikon OPC 模拟器使用教程
随机推荐
MySQL constraint and aggregate query
1800万引进23名菲律宾博士引热议,学校老师回应:权宜之计
My notepad++ plug-in recommendation
FileUploadBase$SizeLimitExceededException
第3章业务功能开发(修改市场活动备注)
[go language] (I) environment building and understanding vscode tools
The introduction of 23 Filipino doctors for 18million was a hot topic, and the school teacher responded: expedient
Matrikon OPC simulator tutorial
M matlab based IEEE802.15.4 home network efficient and energy-saving effective access method
Apple and other big factories can't hold anymore! Layoffs and slowing recruitment, "two pronged" plan
C language program environment and preprocessing
我创建了clickhouse引擎,但是创建SQL节点以后,显示已解绑?这种情况是怎么回事
Makefile implémente les statistiques de temps de compilation
基于NIO模式下通信项目
Typescript正则之前后断言与具名组和解构
面试必刷TOP101 【链表】
包揽数理化国际奥赛全部第一,全员金牌,网友:中国队太秀了
MySQL的安装教程(嗷嗷详细,包教包会~)
Getting started with functions
Mysql八股