Skip to content

Commit

Permalink
recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
codebasics committed Feb 10, 2021
1 parent 3034b38 commit 3174849
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions algorithms/8_recursion/recursion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def find_sum(n):
if n==1:
return 1
return n + find_sum(n-1)

def fib(n):
# 0,1,1,2,3,5,8 <-- fibonacci numbers
# --------------
# 0,1,2,3,4,5,6 <-- index
if n==0 or n==1:
return n
return fib(n-1) + fib(n-2)

if __name__=='__main__':
print(find_sum(5))
print(fib(10))

0 comments on commit 3174849

Please sign in to comment.