Skip to content

Commit

Permalink
add recurcive version
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysiekFel committed Jan 1, 2024
1 parent c28fbcc commit 02832cf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion homework/fibonacci/fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ int fibonacci_iterative(int sequence) {
}

int fibonacci_recursive(int sequence) {

if (sequence == 0) {
return 0;
} else if (sequence == 1) {
return 1;
} else {
return fibonacci_recursive(sequence - 1) + fibonacci_recursive(sequence - 2);
}
return 0;
}

0 comments on commit 02832cf

Please sign in to comment.