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
function sumNatural ( n ) { sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } function suminRange ( l , r ) { return sumNatural ( r ) - sumNatural ( l - 1 ) ; } let l = 2 ; let r = 5 ; document . write ( " " + suminRange ( l , r ) ) ;