Sum of squares of first n natural numbers | CPP Program to find sum of square of first n natural numbers ; Return the sum of square of first n natural numbers ; Iterate i from 1 and n finding square of i and add to sum . ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int squaresum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += ( i * i ) ; return sum ; } int main ( ) { int n = 4 ; cout << squaresum ( n ) << endl ; return 0 ; }