From 04490a5a38b12a2173866e6eafc4625aaf0a0cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszczy=C5=84ski?= <85461555+Rafal-Leszczynski@users.noreply.github.com> Date: Thu, 28 Mar 2024 04:30:57 +0100 Subject: [PATCH] Update fibonacci.hpp --- homework/fibonacci/fibonacci.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/homework/fibonacci/fibonacci.hpp b/homework/fibonacci/fibonacci.hpp index c3c055d4..9357704a 100644 --- a/homework/fibonacci/fibonacci.hpp +++ b/homework/fibonacci/fibonacci.hpp @@ -2,9 +2,9 @@ int fibonacci_iterative(int sequence) { int a = 0, b = 1, temp; - if (sequence ==0) + if (sequence == 0) return a; - for (int i = 2; i <= sequence; i++) { + for (int i = 2; i <= sequence; ++i) { temp = a + b; a = b; b = temp; @@ -17,3 +17,10 @@ int fibonacci_recursive(int sequence) { return sequence; return fibonacci_recursive(sequence - 1) + fibonacci_recursive(sequence - 2); } + +int main() { + std::cout << fibonacci_iterative(10) << "\n"; + std::cout << fibonacci_recursive(10) << "\n"; + + return 0; +}