Q. Print the series which starts with 1, 1, 2…. Every next number is defined as:

(pre1 * pre2 + pre3) For nth term, prev1 is the last number, prev2 is the second last number, and prev3 is the third last number (N >= 3), i.e. series progresses as:

 

…..pev3, prev2, perv1, Nth term

 

Answer = 

 

num = int(input("Enter a number :-"))
prev1 = 1
prev2 = 1
prev3 = 2
print(prev1,prev2,prev3,end=" ")
for i in range (num-3):
    sum = prev1 * prev2 + prev3
    prev1,prev2,prev3 = prev2,prev3,sum
    print(sum,end=" ")

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post