-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.cpp
More file actions
48 lines (39 loc) · 839 Bytes
/
fibonacci.cpp
File metadata and controls
48 lines (39 loc) · 839 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
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
//Fibonacci series
// 0 1 1 2 3 5 8 13
// Third no is sum of previous two numbers
// using golden ratio
// int fib(int n){
// vector<int> F = {0, 1, 1, 2, 3, 5, }
// if (n < 6){
// return F[n];
// }
// }
// void formula(int n){
// double phi = (1 + sqrt(5))/2;
// int ans = round(n-1 * phi);
// cout << ans;
// }
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
if (num == 1){
cout << "0\n";
}else if (num == 2){
cout << "0 1\n";
}else{
long long a=0,b=1,c=3;
long long sum;
cout << a << " " << b << " ";
while(c <= num){
sum = a + b;
cout << sum << " ";
a = b;
b = sum;
c++;
}
}
return 0;
}