Find n | Program to calculate nth term of a series ; func for calualtion ; for summation of square of first n - natural nos . ; summation of first n natural nos . ; return result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int seriesFunc ( int n ) { int sumSquare = ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; int sumNatural = ( n * ( n + 1 ) / 2 ) ; return ( sumSquare + sumNatural + 1 ) ; } int main ( ) { int n = 8 ; cout << seriesFunc ( n ) << endl ; n = 13 ; cout << seriesFunc ( 13 ) ; return 0 ; }