Find the Sum of the series 1 / 2 | Function to find the sum of series ; Generate the ith term and add it to the sum if i is even and subtract if i is odd ; Print the sum ; Driver Code
function printSeriesSum ( N ) { let sum = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { if ( i & 1 ) { sum += i / ( i + 1 ) ; } else { sum -= i / ( i + 1 ) ; } } document . write ( sum . toFixed ( 6 ) ) ; } let N = 10 ; printSeriesSum ( N ) ;