Sum of alternating sign cubes of first N Natural numbers | C ++ implementation to compute the sum of cubes with alternating sign ; Function to compute sum of the cubes with alternating sign ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int summation ( int N ) { int co = ( N + 1 ) / 2 ; int ce = ( N ) / 2 ; int se = 2 * ( ( ce * ( ce + 1 ) ) * ( ce * ( ce + 1 ) ) ) ; int so = ( co * co ) * ( 2 * ( ( co * co ) ) - 1 ) ; return so - se ; } int main ( ) { int n = 3 ; cout << summation ( n ) ; return 0 ; }