Skip to content

Commit

Permalink
Update fibonacci.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal-Leszczynski authored Mar 28, 2024
1 parent 3c8d81c commit 04490a5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions homework/fibonacci/fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

int fibonacci_iterative(int sequence) {
int a = 0, b = 1, temp;
if (sequence ==0)
if (sequence == 0)
return a;
for (int i = 2; i <= sequence; i++) {
for (int i = 2; i <= sequence; ++i) {
temp = a + b;
a = b;
b = temp;
Expand All @@ -17,3 +17,10 @@ int fibonacci_recursive(int sequence) {
return sequence;
return fibonacci_recursive(sequence - 1) + fibonacci_recursive(sequence - 2);
}

int main() {
std::cout << fibonacci_iterative(10) << "\n";
std::cout << fibonacci_recursive(10) << "\n";

return 0;
}

0 comments on commit 04490a5

Please sign in to comment.