- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFib_seq.cpp
More file actions
Latest commit
53 lines (41 loc) · 655 Bytes
/
Copy pathFib_seq.cpp
File metadata and controls
53 lines (41 loc) · 655 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
49
50
51
52
53
#include<iostream>
usingnamespacestd;
int F[51];
intfib (int n)
{
if (n <= 1)
{
return n;
}
if(F[n] != -1)
{
return F[n];
}
/*
int F1,F2,F;
F1 = 0;
F2 = 1;
for (int i = 2; i <= n; i++)
{
F = F1 + F2;
F1 = F2;
F2 = F;
}
return F;
*/
returnfib(n-1) + fib(n-2);
}
intmain()
{
for (int i = 0; i < 51; i++)
{
F[i] = -i;
}
F[0] = 0, F[1] = 1;
int n;
cout << "Enter any number: ";
cin >> n;
int result = fib(n);
cout << result;
return0;
}