Program for N-th term of Geometric Progression series
Given first term (a), common ratio (r) and a integer N of the Geometric Progression series, the task is to find Nth term of the series.
Examples :
Input : a = 2 r = 2, N = 4 Output : The 4th term of the series is : 16 Input : a = 2 r = 3, N = 5 Output : The 5th term of the series is : 162
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 find the Nth term in the Geometric Progression series we use the simple formula .
TN = a1 * r(N-1)
C++
// CPP Program to find nth term of // geometric progression #include <bits/stdc++.h> using namespace std; int Nth_of_GP(int a, int r, int N) { // using formula to find // the Nth term // TN = a1 * r(N-1) return( a * (int)(pow(r, N - 1)) ); } // Driver code int main() { // starting number int a = 2; // Common ratio int r = 3; // N th term to be find int N = 5; // Display the output cout << "The "<< N <<"th term of the series is : " << Nth_of_GP(a, r, N); return 0; } |
Java
// java program to find nth term // of geometric progression import java.io.*; import java.lang.*; class GFG { public static int Nth_of_GP(int a, int r, int N) { // using formula to find the Nth // term TN = a1 * r(N-1) return ( a * (int)(Math.pow(r, N - 1)) ); } // Driver code public static void main(String[] args) { // starting number int a = 2; // Common ratio int r = 3; // N th term to be find int N = 5; // Display the output System.out.print("The "+ N + "th term of the" + " series is : " + Nth_of_GP(a, r, N)); } } |
Python3
# Python3 Program to find nth # term of geometric progression import math def Nth_of_GP(a, r, N): # Using formula to find the Nth # term TN = a1 * r(N-1) return( a * (int)(math.pow(r, N - 1)) ) # Driver code a = 2 # Starting number r = 3 # Common ratio N = 5 # N th term to be find print("The", N, "th term of the series is :", Nth_of_GP(a, r, N)) # This code is contributed by Smitha Dinesh Semwal |
C#
// C# program to find nth term // of geometric progression using System; class GFG { public static int Nth_of_GP(int a, int r, int N) { // using formula to find the Nth // term TN = a1 * r(N-1) return ( a * (int)(Math.Pow(r, N - 1)) ); } // Driver code public static void Main() { // starting number int a = 2; // Common ratio int r = 3; // N th term to be find int N = 5; // Display the output Console.Write("The "+ N + "th term of the" + " series is : " + Nth_of_GP(a, r, N)); } } // This code is contributed by vt_m |
PHP
<?php // PHP Program to find nth term of // geometric progression function Nth_of_GP($a, $r, $N) { // using formula to find // the Nth term TN = a1 * r(N-1) return( $a * (int)(pow($r, $N - 1)) ); } // Driver code // starting number $a = 2; // Common ratio $r = 3; // N th term to be find $N = 5; // Display the output echo("The " . $N . "th term of the series is : " . Nth_of_GP($a, $r, $N)); // This code is contributed by Ajit. ?> |
Output :
The 5th term of the series is : 162
Recommended Posts:
- Program for N-th term of Arithmetic Progression series
- Program to print GP (Geometric Progression)
- Program for sum of geometric series
- Geometric Progression
- Program to print Arithmetic Progression series
- Number of GP (Geometric Progression) subsequences of size 3
- Removing a number from array to make it Geometric Progression
- Minimum number of operations to convert a given sequence into a Geometric Progression
- Program to find Nth term of the series 3 , 5 , 21 , 51 , 95 , ...
- Program to find Nth term of series 9, 23, 45, 75, 113...
- Program to find the N-th term of series 3, 5, 33, 35, 53…. | Set-2
- Program to find Nth term of series 2, 12, 28, 50, 77, 112, 152, 198, .....
- Program to find Nth term of series 4, 14, 28, 46, 68, 94, 124, 158, .....
- Program to find Nth term of series 0, 11, 28, 51, 79, 115, 156, 203, ....
- Program to find Nth term of series 0, 9, 22, 39, 60, 85, 114, 147, .....
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.



