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
< ? php function nearestSmallerEqFib ( $ n ) { if ( $ n == 0 $ n == 1 ) return $ n ; $ f1 = 0 ; $ f2 = 1 ; $ f3 = 1 ; while ( $ f3 <= $ n ) { $ f1 = $ f2 ; $ f2 = $ f3 ; $ f3 = $ f1 + $ f2 ; } return $ f2 ; } function printFibRepresntation ( $ n ) { while ( $ n > 0 ) { $ f = nearestSmallerEqFib ( $ n ) ; echo $ f , " " ; $ n = $ n - $ f ; } } $ n = 30 ; echo " Non - neighbouring ▁ Fibonacci ▁ Representation ▁ of ▁ " , $ n , " ▁ is ▁ STRNEWLINE " ; printFibRepresntation ( $ n ) ; ? >