From e4f4f2a78a27c864866b66155164d1992a528c2d Mon Sep 17 00:00:00 2001 From: Pulsarnixx Date: Sat, 29 Aug 2026 16:21:29 +0200 Subject: [PATCH 1/2] Fibonacci interative done. --- homework/fibonacci/fibonacci.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/homework/fibonacci/fibonacci.hpp b/homework/fibonacci/fibonacci.hpp index 3faab622..bb42437f 100644 --- a/homework/fibonacci/fibonacci.hpp +++ b/homework/fibonacci/fibonacci.hpp @@ -1,7 +1,22 @@ #pragma once int fibonacci_iterative(int sequence) { - // TODO: Your implementation goes here + if (sequence > 0) { + int n1{0}; + int n2{1}; + + int result{0}; + + do { + result = n2 + n1; + n1 = n2; + n2 = result; + + } while (--sequence > 1); + + return result; + } + return 0; } From ab66fd0047c46f73a1d1f5a7a85c5fc53fea1658 Mon Sep 17 00:00:00 2001 From: Pulsarnixx Date: Sat, 29 Aug 2026 16:26:23 +0200 Subject: [PATCH 2/2] Fibonacci recursive done. --- homework/fibonacci/fibonacci.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homework/fibonacci/fibonacci.hpp b/homework/fibonacci/fibonacci.hpp index bb42437f..6c2218bd 100644 --- a/homework/fibonacci/fibonacci.hpp +++ b/homework/fibonacci/fibonacci.hpp @@ -21,6 +21,12 @@ int fibonacci_iterative(int sequence) { } int fibonacci_recursive(int sequence) { - // TODO: Your implementation goes here + if (sequence >= 1) { + if (sequence == 1) { + return 1; + } + return fibonacci_recursive(sequence - 1) + fibonacci_recursive(sequence - 2); + } + return 0; }