📜  十二边形数

📅  最后修改于: 2021-05-07 01:21:41             🧑  作者: Mango

给定数字n,找到第n个十二边形数字。十二边形数字表示十二边形(具有12个边的多边形)。
十二边形的一些数字是:
1,12,33,64,105,156,217,288,369,460,561,672,793,924……..……
例子 :

Input : n = 4
Output : 64

Input : n = 9
Output : 369

十二边形数的第n项的公式:

n-th Dodecagonal number = 5n2 - 4n

下面是第n个十二边形数的实现:

C++
// CPP Program to find the
// nth Dodecagonal number
#include 
using namespace std;
 
// function for Dodecagonal
// number
int Dodecagonal_number(int n)
{
    // formula for find Dodecagonal
    // nth term
    return 5 * n * n - 4 * n;
}
 
// Driver Code
int main()
{
 
    int n = 7;
    cout << Dodecagonal_number(n) << endl;
 
    n = 12;
    cout << Dodecagonal_number(n) << endl;
 
    return 0;
}


Java
// Java program to find the
// nth Dodecagonal number
import java.util.*;
 
class GFG
{
 
    // function for
    // Dodecagonal number
    static int Dodecagonal_number(int n)
    {
        // formula for find
        // Dodecagonal nth term
        return 5 * n * n - 4 * n;
    }
     
    // Driver Code
    public static void main(String[] args)
    {
 
    int n = 7;
    System.out.println(Dodecagonal_number(n));
 
    n = 12;
    System.out.println(Dodecagonal_number(n));
 
    }
}
 
// This code is contributed by Anuj_67


Python3
# Python program to find
# nth Dodecagonal number
 
# Function to calculate
# Dodecagonal number
def Dodecagonal_number(n):
 
    # Formula to calculate nth
    # Dodecagonal number
     
    return  5 * n * n - 4 * n
 
# Driver Code
n = 7
print(Dodecagonal_number(n))
 
n = 12
print(Dodecagonal_number(n))
                     
# This code is contributed by aj_36.


C#
// C# program to find the nth Dodecagonal
// number
using System;
 
class GFG {
 
    // function for Dodecagonal
    // number
    static int Dodecagonal_number(int n)
    {
        // formula for find Dodecagonal
        // nth term
        return 5 * n * n - 4 * n;
    }
     
    // Driver Code
    static void Main()
    {
     
        int n = 7;
        Console.WriteLine(Dodecagonal_number(n));
     
        n = 12;
        Console.WriteLine(Dodecagonal_number(n));
     
    }
}
 
// This code is contributed by Anuj_67


PHP


Javascript


输出 :
217
672

参考: https : //en.wikipedia.org/wiki/Dodecagonal_number