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