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 103e634Copy full SHA for 103e634
homework/fibonacci/fibonacci.hpp
@@ -1,8 +1,14 @@
1
#pragma once
2
3
int fibonacci_iterative(int sequence) {
4
- // TODO: Your implementation goes here
5
- return 0;
+ int current_number{0};
+ int next_number{1};
6
+ for (int i{0}; i < sequence; ++i) {
7
+ int new_number = current_number + next_number;
8
+ current_number = next_number;
9
+ next_number = new_number;
10
+ }
11
+ return current_number;
12
}
13
14
int fibonacci_recursive(int sequence) {
0 commit comments