# Sum of the first N terms of the series 2, 6, 12, 20, 30…. in c programming

CServer Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

To find the sum of this series, we will first analyze this series.

The series is: 2,6,12,20,30…

## Example

For n = 6
Sum = 112
On analysis, (1+1),(2+4),(3+9),(4+16)...
(1+12), (2+22), (3+32), (4+42), can be divided into two series i.e.
s1:1,2,3,4,5… andS2: 12,2,32,....

Find the sum of first and second using mathematical formula

Sum1 = 1+2+3+4… , sum1 = n*(n+1)/2
Sum2 = 12+22+32+42… , sum1 = n*(n+1)*(2*n +1)/6

## Example

#include <stdio.h>
int main() {
int n = 3;
int sum = ((n*(n+1))/2)+((n*(n+1)*(2*n+1))/6);
printf("the sum series till %d is %d", n,sum);
return 0;
}

## Output

The sum of series till 3 is 20
Updated on 09-Aug-2019 11:21:01