Sum of Fibonacci Numbers in a range | Function to return the nth Fibonacci number ; Function to return the required sum ; Using our deduced result ; Driver code
< ? php function fib ( $ n ) { $ phi = ( 1 + sqrt ( 5 ) ) / 2 ; return ( int ) round ( pow ( $ phi , $ n ) / sqrt ( 5 ) ) ; } function calculateSum ( $ l , $ r ) { $ sum = fib ( $ r + 2 ) - fib ( $ l + 1 ) ; return $ sum ; } $ l = 4 ; $ r = 8 ; echo ( calculateSum ( $ l , $ r ) ) ; ? >