Print first n Fibonacci Numbers using direct formula | Python3 code to print fibonacci numbers till n using direct formula . ; Function to calculate fibonacci using recurrence relation formula ; Using direct formula ; Driver code
import math NEW_LINE def fibonacci ( n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT fib = ( ( pow ( ( 1 + math . sqrt ( 5 ) ) , i ) - pow ( ( 1 - math . sqrt ( 5 ) ) , i ) ) / ( pow ( 2 , i ) * math . sqrt ( 5 ) ) ) ; NEW_LINE print ( int ( fib ) , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT n = 8 ; NEW_LINE fibonacci ( n ) ; NEW_LINE