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