-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathall_fibonacci1.cpp
More file actions
45 lines (36 loc) · 791 Bytes
/
Copy pathall_fibonacci1.cpp
File metadata and controls
45 lines (36 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://youtu.be/JbLEpRy_vTk?list=PL-Jc9J83PIiFj7YSPl2ulcpwy-mwj1SSk
//To print all Fibonacci numbers till N
#include<iostream>
#include<fstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<queue>
#include<deque>
#include<utility>
#include<unordered_map>
#include<set>
#include<map>
#include<unordered_set>
#include<string>
#include<limits.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
int main()
{
int n;
cin>>n;
int first=1,second=1;
if(n==1)
cout<<"1 ";
if(n>=2)
cout<<"1 1 ";
for(int i=3;i<=n;i++) // This loop runs for n-2 times as 2 have already been taken care of
{
int current=first+second;
cout<<current<<" ";
first=second;
second=current;
}
}