📌  相关文章
📜  算术级数系列第N项程序

📅  最后修改于: 2021-05-05 00:15:18             🧑  作者: Mango

给定第一个项(a),共同差(d)和算术级数级数的整数N,任务是找到级数的N项。
例子 :

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

方法:

为了找到算术级数系列中的第N项,我们使用简单的公式。

TN = a1 + (N-1) * d
C++
// CPP Program to find nth term of
// Arithmetic progression
#include 
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 code
int 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
// Java program to find nth term
// of Arithmetic progression
import 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));
    }
}


Python3
# 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 code
a = 2  # starting number
d = 1  # Common difference
N = 5  # N th term to be find
  
# Display the output
print( "The ", N ,"th term of the series is : ",
       Nth_of_AP(a, d, N))
 
 
 
# This code is contributed
# by Nikita Tiwari.


C#
// C# program to find nth term
// of Arithmetic progression
using 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


Javascript


输出 :

The 5th term of the series is : 6