Fibonacci Series
Source Code:
n=input()
a,b = 0,1
l=[]
l.append(a)
l.append(b)
for i in range(n-2):
c=a+b
a=b
b=c
l.append(c)
for i in l:
print i,
Input:
8
Output:
0 1 1 2 3 5 8 13
Non Fibonacci Series
Source Code:
n=input()
a,b = 0,1
l=[]
l.append(a)
l.append(b)
for i in range(n-2):
c=a+b
a=b
b=c
l.append(c)
for i in range(c):
if i not in l:
print i,
a,b = 0,1
l=[]
l.append(a)
l.append(b)
for i in range(n-2):
c=a+b
a=b
b=c
l.append(c)
for i in range(c):
if i not in l:
print i,
Input:
8
Output:
4 6 7 9 10 11 12
0 comments:
Post a Comment