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 3c8d81c commit 04490a5Copy full SHA for 04490a5
homework/fibonacci/fibonacci.hpp
@@ -2,9 +2,9 @@
2
3
int fibonacci_iterative(int sequence) {
4
int a = 0, b = 1, temp;
5
- if (sequence ==0)
+ if (sequence == 0)
6
return a;
7
- for (int i = 2; i <= sequence; i++) {
+ for (int i = 2; i <= sequence; ++i) {
8
temp = a + b;
9
a = b;
10
b = temp;
@@ -17,3 +17,10 @@ int fibonacci_recursive(int sequence) {
17
return sequence;
18
return fibonacci_recursive(sequence - 1) + fibonacci_recursive(sequence - 2);
19
}
20
+
21
+int main() {
22
+ std::cout << fibonacci_iterative(10) << "\n";
23
+ std::cout << fibonacci_recursive(10) << "\n";
24
25
+ return 0;
26
+}
0 commit comments