• 0

Fibonacci sum for the given number

Problem description :

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

In mathematical terms, the sequence F(n) of Fibonacci numbers is defined by the recurrence relation

F(n) = F(n-1) + F(n-2), with seed values F(0) = 0, F(1) = 1, F(2) = 1.

Input : A number >= 0

Output : A Number

Logic :

  • Cached the already calculated fibonacci numbers (aka dynamic programming).
  • If the number is not calculated then call the function again (aka recurssion).

Solution :