From 6b44cada4daae6e9c15526a792157d223be14bf0 Mon Sep 17 00:00:00 2001 From: Konrad Legutko Date: Wed, 9 Sep 2026 20:33:17 +0000 Subject: [PATCH] [feat] Implementation fibonacci --- homework/fibonacci/fibonacci.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/homework/fibonacci/fibonacci.hpp b/homework/fibonacci/fibonacci.hpp index 3faab622..81ab2610 100644 --- a/homework/fibonacci/fibonacci.hpp +++ b/homework/fibonacci/fibonacci.hpp @@ -1,11 +1,22 @@ #pragma once +#include int fibonacci_iterative(int sequence) { - // TODO: Your implementation goes here - return 0; + if (sequence < 1) + return 0; + int a = 0; + int b = 1; + for (size_t i = 0; i < sequence; i++) { + int temp = a; + a = b; + b = temp + b; + } + return a; } 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); }