Sum of alternating sign cubes of first N Natural numbers | Function to compute sum of the cubes with alternating sign ; Driver code
function summation ( N ) { var co = parseInt ( ( N + 1 ) / 2 ) ; var ce = parseInt ( ( N ) / 2 ) ; var se = 2 * ( ( ce * ( ce + 1 ) ) * ( ce * ( ce + 1 ) ) ) ; var so = ( co * co ) * ( 2 * ( ( co * co ) ) - 1 ) ; return so - se ; } var n = 3 ; document . write ( summation ( n ) ) ;