Sum of all odd natural numbers in range L and R | Function to return the sum of all odd natural numbers ; Function to return the sum of all odd numbers in range L and R ; Driver Code
< ? php function sumOdd ( $ n ) { $ terms = ( int ) ( $ n + 1 ) / 2 ; $ sum = $ terms * $ terms ; return $ sum ; } function suminRange ( $ l , $ r ) { return sumOdd ( $ r ) - sumOdd ( $ l - 1 ) ; } $ l = 2 ; $ r = 5 ; echo " Sum ▁ of ▁ odd ▁ natural ▁ numbers ▁ from ▁ L ▁ to ▁ R ▁ is ▁ " , suminRange ( $ l , $ r ) ; ? >