Skip to content

Commit

Permalink
adding works
Browse files Browse the repository at this point in the history
  • Loading branch information
MiKaz003 committed Aug 2, 2024
1 parent 65ed827 commit 35dbe6c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions homework/fibonacci/fibonacci.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#pragma once

int fibonacci_iterative(int sequence) {
// TODO: Your implementation goes here
return 0;
if (sequence == 0){
return 0;
}
int tab[sequence];
tab[0] = 1;
tab[1] = 1;
int current = 1;
for(int i = 2; i < sequence; i++){
tab[i] = tab[i-1] + tab[i-2];
current = tab[i];
}
return current;
}

int fibonacci_recursive(int sequence) {
// TODO: Your implementation goes here
return 0;
if (sequence == 0){
return 0;
}
if (sequence <= 2){
return 1;
}
else {
return fibonacci_recursive(sequence - 1) + fibonacci_recursive(sequence - 2);
}
}

0 comments on commit 35dbe6c

Please sign in to comment.