📜  求系列 2, 8, 18, 32, 50, 的第 n 项。 . . .

📅  最后修改于: 2022-05-13 01:56:08.191000             🧑  作者: Mango

求系列 2, 8, 18, 32, 50, 的第 n 项。 . . .

给定一个整数N ,任务是找到序列的第 N 项

例子:

方法:

从给定的系列中,找到第 N项的公式-

给定系列的第 N项可以概括为-

插图:

以下是上述方法的实现 -

C++
// C++ program to implement
// the above approach
#include 
using namespace std;
 
// Function to return nth
// term of the series
int find_nth_Term(int n)
{
    return 2 * n * n;
}
 
// Driver code
int main()
{
    // Value of N
    int N = 6;
 
    // function call
    cout << find_nth_Term(N) <<
            end;
    return 0;
}


Java
// Java program for the above approach
import java.io.*;
import java.lang.*;
import java.util.*;
 
class GFG {
 
  // Function to return nth
  // term of the series
  static int find_nth_Term(int n)
  {
    return 2 * n * n;
  }
 
  // Driver code
  public static void main (String[] args)
  {
 
    // Value of N
    int N = 6;
 
    // function call
    System.out.println(find_nth_Term(N));
  }
}
 
// This code is contributed by hrithikgarg03188.


Python
# Python program to implement
# the above approach
 
# Find n-th term of series
# 2, 8, 18, 32, 50...
 
def nthTerm(n):
 
    return 2 * n * n;
 
# Driver Code
if __name__ == "__main__":
   
    # Value of N
    N = 6
     
    # function call
    print(nthTerm(N))
 
# This code is contributed by Samim Hossain Mondal.


C#
// C# program to implement
// the above approach
using System;
 
class GFG
{
 
  // Function to return nth
  // term of the series
  static int find_nth_Term(int n)
  {
    return 2 * n * n;
  }
 
  // Driver Code
  public static void Main()
  {
     
    // Value of N
    int N = 6;
 
    // function call
    Console.Write(find_nth_Term(N));
 
  }
}
 
// This code is contributed by sanjoy_62.


Javascript


输出
72

时间复杂度: O(1)
辅助空间: O(1)