📜  第二个六边形数字

📅  最后修改于: 2021-04-24 17:54:57             🧑  作者: Mango

第二个六边形数字系列可以表示为

第N个学期

给定整数N。任务是找到给定级数的第N个项。
例子

方法:想法是找到第二个六边形数字的总称。以下是第二个六角形数的通用项的计算:

下面是上述方法的实现:

C++
// C++ implementation to
// find N-th term
// in the series
#include 
#include 
using namespace std;
 
// Function to find N-th term
// in the series
void findNthTerm(int n)
{
    cout << n * (2 * n + 1) << endl;
}
 
// Driver code
int main()
{
    int N = 4;
    findNthTerm(N);
 
    return 0;
}


Java
// Java implementation to
// find N-th term
// in the series
class GFG{
     
// Function to find N-th term
// in the series
static void findNthTerm(int n)
{
    System.out.print(n * (2 * n + 1));
}
 
// Driver code
public static void main (String[] args)
{
    int N = 4;
    findNthTerm(N);
}
}
 
// This code is contributed by Ritik Bansal


Python3
# Python3 implementation to
# find N-th term
# in the series
 
# Function to find N-th term
# in the series
def findNthTerm(n):
    print(n * (2 * n + 1))
 
# Driver code
N = 4
 
# Function call
findNthTerm(N)
 
# This code is contributed by Vishal Maurya


C#
// C# implementation to
// find N-th term
// in the series
using System;
class GFG{
     
// Function to find N-th term
// in the series
static void findNthTerm(int n)
{
    Console.Write(n * (2 * n + 1));
}
 
// Driver code
public static void Main()
{
    int N = 4;
    findNthTerm(N);
}
}
 
// This code is contributed by Code_Mech


Javascript


输出:
36

参考: OEIS