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