Program for N-th term of Arithmetic Progression series - GeeksforGeeks

25 Feb, 2021
Given first term (a), common difference (d) and a integer N of the Arithmetic Progression series, the task is to find Nthterm of the series.Examples :  
Input : a = 2 d = 1 N = 5
Output :
The 5th term of the series is : 6

Input : a = 5 d = 2 N = 10
Output :
The 10th term of the series is : 23
Approach:  
We know the Arithmetic Progression series is like = 2, 5, 8, 11, 14 .... ... In this series 2 is the stating term of the series . Common difference = 5 – 2 = 3 (Difference common in the series). so we can write the series as :t1 = a1 t2 = a1 + (2-1) * d t3 = a1 + (3-1) * d . . . tN = a1 + (N-1) * d  
To find the Nth term in the Arithmetic Progression series we use the simple formula . 
TN = a1 + (N-1) * d
 
 
C++
Java
Python3
C#
PHP
Javascript
// CPP Program to find nth term of// Arithmetic progression#include <bits/stdc++.h>using namespace std; int Nth_of_AP(int a, int d, int N){    // using formula to find the    // Nth term t(n) = a(1) + (n-1)*d    return (a + (N - 1) * d);     } // Driver codeint main(){    // starting number    int a = 2;         // Common difference    int d = 1;         // N th term to be find    int N = 5;         // Display the output    cout << "The "<< N         <<"th term of the series is : "         << Nth_of_AP(a,d,N);     return 0;}
// Java program to find nth term// of Arithmetic progressionimport java.io.*;import java.lang.*; class GFG{    public static int Nth_of_AP(int a,                                int d,                                int N)    {        // using formula to find the Nth        // term t(n) = a(1) + (n-1)*d        return ( a + (N - 1) * d );    }     // Driver code    public static void main(String[] args)    {        // starting number        int a = 2;                 // Common difference        int d = 1;                 // 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_AP(a, d, N));    }}
# Python 3 Program to# find nth term of# Arithmetic progression def Nth_of_AP(a, d, N) :     # using formula to find the    # Nth term t(n) = a(1) + (n-1)*d    return (a + (N - 1) * d)        # Driver codea = 2  # starting numberd = 1  # Common differenceN = 5  # N th term to be find  # Display the outputprint( "The ", N ,"th term of the series is : ",       Nth_of_AP(a, d, N))   # This code is contributed# by Nikita Tiwari.
// C# program to find nth term// of Arithmetic progressionusing System; class GFG{    public static int Nth_of_AP(int a,                                int d,                                int N)    {                 // using formula to find the Nth        // term t(n) = a(1) + (n-1)*d        return ( a + (N - 1) * d );    }     // Driver code    public static void Main()    {        // starting number        int a = 2;                 // Common difference        int d = 1;                 // N th term to be find        int N = 5;         // Display the output        Console.WriteLine("The "+ N +                          "th term of the series is : " +                           Nth_of_AP(a, d, N));    }} // This code is contributed by vt_m.
<?php// PHP Program to find nth term of// Arithmetic progression function Nth_of_AP($a, $d, $N){    // using formula to find the    // Nth term t(n) = a(1) + (n-1)*d    return ($a + ($N - 1) * $d);     } // Driver code // starting number$a = 2; // Common difference$d = 1; // N th term to be find$N = 5;     // Display the outputecho("The " . $N . "th term of the series is : " .                           Nth_of_AP($a, $d, $N)); // This code is contributed by Ajit.?>
<script> // JavaScript Program to find nth term of // Arithmetic progression     function Nth_of_AP(a, d, N)    {         // using formula to find the         // Nth term t(n) = a(1) + (n-1)*d        return (a + (N - 1) * d);           }       // Driver code     // starting number    let a = 2;            // Common difference    let d = 1;            // N th term to be find    let N = 5;            // Display the output    document.write("The "+ N + "th term of the series is : "    + Nth_of_AP(a,d,N));    // This code is contributed by Mayank Tyagi </script>
Output :  
The 5th term of the series is : 6
 
jit_t
mayanktyagi1709
arithmetic progression
series
Mathematical
School Programming
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Merge two sorted arrays
Modulo Operator (%) in C/C++ with Examples
Program to find GCD or HCF of two numbers
Prime Numbers
Program to find sum of elements in a given array
Python Dictionary
Arrays in C/C++
Inheritance in C++
Reverse a string in Java
Interfaces in Java