Skip to content

Commit

Permalink
adding works
Browse files Browse the repository at this point in the history
  • Loading branch information
VeniGogniti committed Jun 28, 2024
1 parent 4ea5364 commit b206438
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions homework/fibonacci/fibonacci.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#pragma once
#include <iostream>

int fibonacci_iterative(int sequence) {
// TODO: Your implementation goes here
return 0;
int liczbaA = 0;
int liczbaB = 0;
int wynik = 0;
for (int i = 0; i <= sequence; i++) {
wynik = liczbaB + liczbaA;
liczbaA = liczbaB;
liczbaB = wynik;
if (wynik == 0) {
liczbaA = 1;
}
}
return wynik;
}

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

0 comments on commit b206438

Please sign in to comment.