📜  二十面体对角线数

📅  最后修改于: 2021-04-26 05:53:10             🧑  作者: Mango

给定数N ,任务是找到N同义七角形数。

例子:

方法:在数学中,第N同义七角形数由下式给出:

Tn = (19n^2 - 17n)/2

下面是上述方法的实现:

C++
// C++ program to find nth
// Icosihenagonal number
 
#include 
using namespace std;
 
// Function to find
// Icosihenagonal number
int Icosihenagonal_num(int n)
{
    // Formula to calculate nth
    // Icosihenagonal number
    return (19 * n * n - 17 * n) / 2;
}
 
// Driver Code
int main()
{
    int n = 3;
    cout << Icosihenagonal_num(n) << endl;
 
    n = 10;
    cout << Icosihenagonal_num(n) << endl;
 
    return 0;
}


Java
// Java program to find nth
// Icosihenagonal number
class GFG{
 
// Function to find
// Icosihenagonal number
static int Icosihenagonal_num(int n)
{
    // Formula to calculate nth
    // Icosihenagonal number
    return (19 * n * n - 17 * n) / 2;
}
 
// Driver Code
public static void main(String[] args)
{
    int n = 3;
    System.out.print(Icosihenagonal_num(n) + "\n");
 
    n = 10;
    System.out.print(Icosihenagonal_num(n) + "\n");
}
}
 
// This code is contributed by Rajput-Ji


Python3
# Python3 program to find nth
# icosihenagonal number
 
# Function to find
# icosihenagonal number
def Icosihenagonal_num(n):
     
    # Formula to calculate nth
    # icosihenagonal number
    return (19 * n * n - 17 * n) / 2
     
# Driver Code
n = 3
print(int(Icosihenagonal_num(n)))
 
n = 10
print(int(Icosihenagonal_num(n)))
 
# This code is contributed by divyeshrabadiya07


C#
// C# program to find nth
// Icosihenagonal number
using System;
 
class GFG{
 
// Function to find
// Icosihenagonal number
static int Icosihenagonal_num(int n)
{
    // Formula to calculate nth
    // Icosihenagonal number
    return (19 * n * n - 17 * n) / 2;
}
 
// Driver Code
public static void Main()
{
    int n = 3;
    Console.Write(Icosihenagonal_num(n) + "\n");
 
    n = 10;
    Console.Write(Icosihenagonal_num(n) + "\n");
}
}
 
// This code is contributed by Code_Mech


Javascript


输出:
60
865

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