-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ea5364
commit b206438
Showing
1 changed file
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |