Difference between Sum of Cubes and Sum of First N Natural Numbers | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int difference ( int n ) { int S , res ; S = ( n * ( n + 1 ) ) / 2 ; res = S * ( S - 1 ) ; return res ; } int main ( ) { int n = 5 ; cout << difference ( n ) ; return 0 ; }