def fib(x):
f1=0
f2=1
print(f1)
print(f2)
#logic
i=3
while(i<=x):
f3=f1+f2
print(f3)
f1=f2
f2=f3
i=i+1
#main program
x=int(input("Enter the number of terms"))
print("The number of terms: ",x)
fib(x)
Example
Enter the number of terms7 The number of terms: 7 0 1 1 2 3 5 8
No comments:
Post a Comment