Difference between Sum of Cubes and Sum of First N Natural Numbers | JavaScript program to find the difference between the sum of the cubes of the first N natural numbers and the sum of the first N natural number ; Sum of first n natural numbers ; Find the required difference ; Driver Code
function difference ( n ) { let S , res ; S = Math . floor ( ( n * ( n + 1 ) ) / 2 ) ; res = S * ( S - 1 ) ; return res ; } let n = 5 ; document . write ( difference ( n ) ) ;