-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursiveques.py
More file actions
64 lines (42 loc) · 1020 Bytes
/
recursiveques.py
File metadata and controls
64 lines (42 loc) · 1020 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# # def printnto1(n):
# # # base case
# # if n==0:
# # return
# # # print (n)
# # # recursive case
# # printnto1(n-1)
# # print(n)
# # printnto1(7)
# # # sum of 1 to n in recursive
# # def sum(n):
# # # base case
# # if n==1:
# # return 1
# # # recursive case
# # ans=n+sum(n-1)
# # return ans
# # n=int(input("enter n:"))
# # print(sum(n))
# # power resied a to b in recusive
# def power(a,b):
# # base case
# if b==0:
# return 1
# # recursive case
# ans=a *power(a,b-1)
# return ans
# a=int(input("enter a:"))
# b=int(input("enter b:"))
# print(power(a,b))
# fibonacci sequence
def fibonacci(n):
# base case
if n==1:
return 0
elif n==2:
return 1
else:
return (fibonacci(n-1)+fibonacci(n-2))
n=int(input("enter n:"))
for i in range(1,n+1):
print(fibonacci(i ))