Nicomachu 's Theorem | CPP program to verify Nicomachu 's Theorem ; Compute sum of cubes ; Check if sum is equal to given formula . ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void NicomachuTheorum_sum ( int n ) { int sum = 0 ; for ( int k = 1 ; k <= n ; k ++ ) sum += k * k * k ; int triNo = n * ( n + 1 ) / 2 ; if ( sum == triNo * triNo ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int n = 5 ; NicomachuTheorum_sum ( n ) ; return 0 ; }