Skip to content

Commit 812f9be

Browse files
committed
adding works
1 parent 65ed827 commit 812f9be

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

homework/fibonacci/fibonacci.hpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
#pragma once
22

33
int fibonacci_iterative(int sequence) {
4-
// TODO: Your implementation goes here
5-
return 0;
4+
int result=0;
5+
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+
625
}
726

827
int fibonacci_recursive(int sequence) {
9-
// TODO: Your implementation goes here
10-
return 0;
28+
int i=0;
29+
i++;
30+
int result=0;
31+
if(sequence==0)
32+
{
33+
return 0;
34+
}
35+
else if(sequence==1)
36+
{
37+
return 1;
38+
}
39+
else
40+
{
41+
result=fibonacci_recursive(sequence-2)+fibonacci_recursive(sequence-1);
42+
}
43+
return result;
1144
}

0 commit comments

Comments
 (0)