Zeckendorf 's Theorem (Non | Returns the greatest Fibonacci Number smaller than or equal to n . ; Corner cases ; Find the greatest Fibonacci Number smaller than n . ; Prints Fibonacci Representation of n using greedy algorithm ; Find the greates Fibonacci Number smaller than or equal to n ; Print the found fibonacci number ; Reduce n ; Driver Code
function nearestSmallerEqFib ( n ) { if ( n == 0 n == 1 ) return n ; let f1 = 0 ; let f2 = 1 ; let f3 = 1 ; while ( f3 <= n ) { f1 = f2 ; f2 = f3 ; f3 = f1 + f2 ; } return f2 ; } function printFibRepresntation ( n ) { while ( n > 0 ) { let f = nearestSmallerEqFib ( n ) ; document . write ( f , " " ) ; n = n - f ; } } let n = 30 ; document . write ( " " + n + " " ) ; printFibRepresntation ( n ) ;