Given first term (a), common ratio (r) and a integer n of the Geometric Progression series, the task is to print th n terms of the series.

Examples:

Input : a = 2 r = 2, n = 4 Output : 2 4 8 16

**Approach :**

We know the Geometric Progression series is like = 2, 4, 8, 16, 32 …….

In this series 2 is the stating term of the series .

Common ratio = 4 / 2 = 2 (ratio common in the series).

so we can write the series as :

t1 = a1

t2 = a1 * r^{(2-1)}

t3 = a1 * r^{(3-1)}

t4 = a1 * r^{(4-1)}

.

.

.

.

tN = a1 * r^{(n-1)}

To print the Geometric Progression series we use the simple formula .

T_{N}= a1 * r^{(n-1)}

## CPP

`// CPP program to print GP. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `void` `printGP(` `int` `a, ` `int` `r, ` `int` `n) ` `{ ` ` ` `int` `curr_term; ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` `curr_term = a * ` `pow` `(r, i); ` ` ` `cout << curr_term << ` `" "` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `a = 2; ` `// starting number ` ` ` `int` `r = 3; ` `// Common ratio ` ` ` `int` `n = 5; ` `// N th term to be find ` ` ` `printGP(a, r, n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to print GP. ` `class` `GFG { ` ` ` `static` `void` `printGP(` `int` `a, ` `int` `r, ` `int` `n) ` ` ` `{ ` ` ` `int` `curr_term; ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) { ` ` ` `curr_term = a * (` `int` `)Math.pow(r, i); ` ` ` `System.out.print(curr_term + ` `" "` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `a = ` `2` `; ` `// starting number ` ` ` `int` `r = ` `3` `; ` `// Common ratio ` ` ` `int` `n = ` `5` `; ` `// N th term to be find ` ` ` `printGP(a, r, n); ` ` ` `} ` `} ` `// This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 program to print GP. ` ` ` `def` `printGP(a, r, n): ` ` ` `for` `i ` `in` `range` `(` `0` `, n): ` ` ` `curr_term ` `=` `a ` `*` `pow` `(r, i) ` ` ` `print` `(curr_term, end ` `=` `" "` `) ` ` ` ` ` `# Driver code ` ` ` `a ` `=` `2` `# starting number ` `r ` `=` `3` `# Common ratio ` `n ` `=` `5` `# N th term to be find ` ` ` `printGP(a, r, n) ` ` ` `# This code is contributed by ` `# Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

## C#

`// C# program to print GP. ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `static` `void` `printGP(` `int` `a, ` `int` `r, ` `int` `n) ` ` ` `{ ` ` ` ` ` `int` `curr_term; ` ` ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` `curr_term = a * (` `int` `)Math.Pow(r, i); ` ` ` `Console.Write(curr_term + ` `" "` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `int` `a = 2; ` `// starting number ` ` ` `int` `r = 3; ` `// Common ratio ` ` ` `int` `n = 5; ` `// N th term to be find ` ` ` ` ` `printGP(a, r, n); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to print GP. ` ` ` `// function to print GP ` `function` `printGP(` `$a` `, ` `$r` `, ` `$n` `) ` `{ ` ` ` `for` `(` `$i` `= 0; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `{ ` ` ` `$curr_term` `= ` `$a` `* pow(` `$r` `, ` `$i` `); ` ` ` `echo` `$curr_term` `, ` `" "` `; ` ` ` `} ` `} ` ` ` ` ` `// Driver Code ` ` ` ` ` `// starting number ` ` ` `$a` `= 2; ` ` ` ` ` `// Common ratio ` ` ` `$r` `= 3; ` ` ` ` ` `// N th term to be find ` ` ` `$n` `= 5; ` ` ` `printGP(` `$a` `, ` `$r` `, ` `$n` `); ` ` ` `// This code is contributed by ajit. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2 6 18 54 162

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program for N-th term of Geometric Progression series
- Removing a number from array to make it Geometric Progression
- Number of GP (Geometric Progression) subsequences of size 3
- Minimum number of operations to convert a given sequence into a Geometric Progression
- Geometric Progression
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Sum of N-terms of geometric progression for larger values of N | Set 2 (Using recursion)
- Sum of elements of a Geometric Progression (GP) in a given range
- Program to print Arithmetic Progression series
- Program for sum of geometric series
- Program for N-th term of Arithmetic Progression series
- Geometric mean (Two Methods)
- Find Harmonic mean using Arithmetic mean and Geometric mean
- Number of terms in Geometric Series with given conditions
- Sum of Arithmetic Geometric Sequence
- Find N Geometric Means between A and B
- Integer part of the geometric mean of the divisors of N
- Product of N terms of a given Geometric series
- Find the missing number in Arithmetic Progression
- Minimum De-arrangements present in array of AP (Arithmetic Progression)

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.