diff --git a/algorithms/CPlusPlus/Recursion/fibonacci.cpp b/algorithms/CPlusPlus/Recursion/fibonacci.cpp index 30e2953d..45591a4e 100644 --- a/algorithms/CPlusPlus/Recursion/fibonacci.cpp +++ b/algorithms/CPlusPlus/Recursion/fibonacci.cpp @@ -1,20 +1,24 @@ /* Description: Program to calculate fibonacci using recursion + + Time complexity: O(2^n) where n is the number */ #include using namespace std; +//Recursive function with integer parameter int RecursiveFibonacci(int number) { - if(number == 1 || number == 2) + if(number == 0 || number == 1) return 1; - if(number >= 3) + if(number >= 2) return RecursiveFibonacci(number - 1) + RecursiveFibonacci(number - 2); return 0; } +//Main function int main(int argc, char *argv[]) { int number = 10;