Print first n Fibonacci Numbers using direct formula | Function to calculate fibonacci using recurrence relation formula ; Using direct formula ; Driver code
function fibonacci ( n ) { var fib ; for ( i = 0 ; i < n ; i ++ ) { fib = ( Math . pow ( ( 1 + Math . sqrt ( 5 ) ) , i ) - Math . pow ( ( 1 - Math . sqrt ( 5 ) ) , i ) ) / ( Math . pow ( 2 , i ) * Math . sqrt ( 5 ) ) ; document . write ( parseInt ( fib ) + " " ) ; } } var n = 8 ; fibonacci ( n ) ;