chore(Python): added to recursion n-th_fibonacci_number (#451)

Co-authored-by: Arsenic <54987647+Arsenic-ATG@users.noreply.github.com>
pull/454/head
Mohammad Shakib 2021-09-08 18:48:44 +06:00 committed by GitHub
parent fc70e7f0f5
commit ac710c7bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -19,6 +19,7 @@
## Recursion ## Recursion
1. [Factorial](recursion/factorial.py) 1. [Factorial](recursion/factorial.py)
2. [n-th Fibonacci number](recursion/n-th_fibonacci_number.py)
## Scheduling ## Scheduling

View File

@ -0,0 +1,18 @@
# Function for nth fibonacci number - Using recursion
# Taking 1st two fibonacci numbers as 0 and 1
FibArray = [1]
def fibonacci(n):
if n<0:
print("Incorrect input")
if n == 0:
return 0
elif n<= len(FibArray):
return FibArray[n-1]
else:
temp_fib = fibonacci(n-1)+fibonacci(n-2)
FibArray.append(temp_fib)
return temp_fib
# Driver Program
print(fibonacci(100))