-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday17(Recursions).py
More file actions
47 lines (38 loc) · 871 Bytes
/
day17(Recursions).py
File metadata and controls
47 lines (38 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# function ke andar usse same fuction ko call krte
# factorial(7) = 7*6*5*4*3*2*1
# factorial(6) = 6*5*4*3*2*1
# factorial(5) = 5*4*3*2*1
# factorial(4) = 4*3*2*1
# factorial(0) = 1
# factorial(n) = n * factorial(n-1)
def factorial(n):
if(n==0 or n==1):
return 1
else:
return(n* factorial(n-1))
print(factorial(4))
print(factorial(2))
print(factorial(0))
# 5 * factorial(4)
# 5 * 4 * factorial(3)
# 5 * 4 * 3 * factorial(2)
# 5 * 4 * 3 * 2 * factorial(1)
# 5 * 4 * 3 * 2 * 1
#FIBBONACCI SERIES
# f(0) = 0
# f(1) = 1
# f(2) = f(1) + f(0)
# f(n) = f(n-1) + f(n-2)
# 0 1 1 2 3 5 8....
def Fibbonacci(n):
if(n==0):
return 0
elif(n==1):
return 1
else:
return(Fibbonacci(n-1)+Fibbonacci(n-2))
print(Fibbonacci(3))
print(Fibbonacci(0))
print(Fibbonacci(1))
print(Fibbonacci(2))
print(Fibbonacci(5))