From 35dbe6c0b5724d598790ef76d1ba24ba2e516661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ka=C5=BAmierczak?= Date: Fri, 2 Aug 2024 11:58:31 +0200 Subject: [PATCH] adding works --- homework/fibonacci/fibonacci.hpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/homework/fibonacci/fibonacci.hpp b/homework/fibonacci/fibonacci.hpp index 3faab622..e267acda 100644 --- a/homework/fibonacci/fibonacci.hpp +++ b/homework/fibonacci/fibonacci.hpp @@ -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); + } }