Sum of first n natural numbers | CPP program to find sum series 1 , 3 , 6 , 10 , 15 , 21. . . and then find its sum ; Function to find the sum of series ; Driver code
#include <iostream> NEW_LINE using namespace std ; int seriesSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += i * ( i + 1 ) / 2 ; return sum ; } int main ( ) { int n = 4 ; cout << seriesSum ( n ) ; return 0 ; }