Sum of squares of first n natural numbers | CPP Program to find sum of square of first n natural numbers . This program avoids overflow upto some extent for large value of n . ; Return the sum of square of first n natural numbers ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int squaresum ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; } int main ( ) { int n = 4 ; cout << squaresum ( n ) << endl ; return 0 ; }