Dynamic Fibonacci Python

PROGRAM TO IMPLEMENT DYNAMIC PROGRAM FOR FIBONACCI NUMBER



def printFibonacciNumbers(n):
 
    f1 = 0
    f2 = 1
    if (n < 1):
        return
    print(f1, end=" ")
    for x in range(1, n):
        print(f2, end=" ")
        next = f1 + f2
        f1 = f2
        f2 = next
 
 
# Driven code
printFibonacciNumbers(7)

OUTPUT:
0 1 1 2 3 5 8

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java