We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 65ed827 commit 812f9beCopy full SHA for 812f9be
homework/fibonacci/fibonacci.hpp
@@ -1,11 +1,44 @@
1
#pragma once
2
3
int fibonacci_iterative(int sequence) {
4
- // TODO: Your implementation goes here
5
- return 0;
+ int result=0;
+ int f1=1;
6
+ int temp=0;
7
+ if(sequence==0)
8
+ {
9
+ return 0;
10
+ }
11
+ else if(sequence==1)
12
13
+ return 1;
14
15
+
16
+ for(int i=2; i<=sequence; ++i)
17
18
+ result=temp+f1;
19
+ temp=f1;
20
+ f1=result;
21
22
23
+ return result;
24
25
}
26
27
int fibonacci_recursive(int sequence) {
28
+ int i=0;
29
+ i++;
30
31
32
33
34
35
36
37
38
39
+ else
40
41
+ result=fibonacci_recursive(sequence-2)+fibonacci_recursive(sequence-1);
42
43
44
0 commit comments