# Find the sum of series 3, -6, 12, -24 . . . upto N terms

Given an integer **N**. The task is to find the **sum** upto **N terms** of the given series:

3, -6, 12, -24, … upto N terms

**Examples**:

Input : N = 5 Output : Sum = 33 Input : N = 20 Output : Sum = -1048575

On observing the given series, it can be seen that the ratio of every term with their previous term is same which is **-2**. Hence the given series is a GP(Geometric Progression) series.

You can learn more about GP series here.

So, when r < 0.

In above GP series the first term i:e **a = 3** and common ratio i:e **r = (-2)**.

Therefore, .

Thus, .

Below is the implementation of above approach:

## C++

`//C++ program to find sum upto N term of the series: ` `// 3, -6, 12, -24, ..... ` ` ` `#include<iostream> ` `#include<math.h> ` `using` `namespace` `std; ` `//calculate sum upto N term of series ` ` ` `class` `gfg ` `{ ` ` ` `public` `: ` ` ` `int` `Sum_upto_nth_Term(` `int` `n) ` ` ` `{ ` ` ` `return` `(1 - ` `pow` `(-2, n)); ` ` ` `} ` `}; ` `// Driver code ` `int` `main() ` `{ ` ` ` `gfg g; ` ` ` `int` `N = 5; ` ` ` `cout<<g.Sum_upto_nth_Term(N); ` `} ` |

*chevron_right*

*filter_none*

## Java

`//Java program to find sum upto N term of the series: ` `// 3, -6, 12, -24, ..... ` ` ` `import` `java.util.*; ` `//calculate sum upto N term of series ` ` ` `class` `solution ` `{ ` ` ` `static` `int` `Sum_upto_nth_Term(` `int` `n) ` `{ ` ` ` `return` `(` `1` `-(` `int` `)Math.pow(-` `2` `, n)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String arr[]) ` `{ ` ` ` `int` `N = ` `5` `; ` ` ` `System.out.println(Sum_upto_nth_Term(N)); ` `} ` ` ` `} ` |

*chevron_right*

*filter_none*

## Python

`# Python program to find sum upto N term of the series: ` `# 3, -6, 12, -24, ..... ` ` ` `# calculate sum upto N term of series ` `def` `Sum_upto_nth_Term(n): ` ` ` `return` `(` `1` `-` `pow` `(` `-` `2` `, n)) ` ` ` `# Driver code ` `N ` `=` `5` `print` `(Sum_upto_nth_Term(N)) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find sum upto ` `// N term of the series: ` `// 3, -6, 12, -24, ..... ` ` ` `// calculate sum upto N term of series ` `class` `GFG ` `{ ` ` ` `static` `int` `Sum_upto_nth_Term(` `int` `n) ` `{ ` ` ` `return` `(1 -(` `int` `)System.Math.Pow(-2, n)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `N = 5; ` ` ` `System.Console.WriteLine(Sum_upto_nth_Term(N)); ` `} ` `} ` ` ` `// This Code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

**Output:**

33

## Recommended Posts:

- Find sum of the series ?3 + ?12 +......... upto N terms
- Find the sum of series 0.X + 0.XX + 0.XXX +... upto k terms
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ..... upto n terms
- Find the sum of the series 1+11+111+1111+..... upto n terms
- Find sum of the series 1+22+333+4444+...... upto n terms
- Program to find the sum of the series 23+ 45+ 75+..... upto N terms
- Sum of the series (1*2) + (2*3) + (3*4) + ...... upto n terms
- Sum of series 2/3 - 4/5 + 6/7 - 8/9 + ------- upto n terms
- Sum of the series 0.7, 0.77, 0.777, ... upto n terms
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + - - - - - - upto n terms.
- Find n terms of Fibonacci type series with given first two terms
- Find the sum of first N terms of the series 2×3 + 4×4 + 6×5 + 8×6 + ...
- Find the sum of n terms of the series 1,8,27,64 ....
- Find the sum of first N terms of the series 2*3*5, 3*5*7, 4*7*9, ...
- Find the sum of all the terms in the n-th row of the given series

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.