📜  十边形数

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

给定数字n,任务是找到第n个十角形数字。
十角形数是数学上的19边形多边形。它属于一类象征数字。数字包含点的数量,并且点以图案或系列排列。十角形数也称为九十进制。这些点具有公共点,而所有其他点都排列在连续的层中。

例子 :

十边形数
查找第n个十角形数的公式:

  \begin{math}  Ed_{n}=((17n^2)-15n)/2 \end{math}

C++
// C++ program to find
// nth Enneadecagonal number
#include 
using namespace std;
  
// Function to calculate 
// Enneadecagonal number
int nthEnneadecagonal(long int n)
{
    // Formula for finding
    // nth Enneadecagonal number
    return (17 * n * n - 15 * n) / 2;
}
  
// Drivers code
int main()
{
    long int n = 6;
    cout << n << "th Enneadecagonal number :" << nthEnneadecagonal(n);
    return 0;
}


Java
// Java program to find
// nth Enneadecagonal number
import java.io.*;
  
class GFG {
  
    // Function to calculate 
    // Enneadecagonal number
    static int nthEnneadecagonal(int n)
    {
          
        // Formula for finding
        // nth Enneadecagonal number
        return (17 * n * n - 15 * n) / 2;
    }
      
    // Driver Code
    public static void main (String[] args)
    {
          
        int n = 6;
        System.out.print(n + "th Enneadecagonal number :");
      
        System.out.println( nthEnneadecagonal(n));
    }
}
  
// This code is contributed by m_kit.


Python3
# Program to find nth
# Enneadecagonal number
  
def nthEnneadecagonal(n) :
      
    # Formula to calculate nth
    # Enneadecagonal number
    return (17 * n * n - 15 * n) // 2
  
# Driver Code
if __name__ == '__main__' :
          
    n = 6
    print(n,"th Enneadecagonal number :"
                , nthEnneadecagonal(n))
  
# This code is contributed  by Ajit


C#
// C# program to find
// nth Enneadecagonal number
using System;
  
class GFG
{
    // Function to calculate 
    // Enneadecagonal number
    static int nthEnneadecagonal(int n)
    {
          
    // Formula for finding
    // nth Enneadecagonal number
    return (17 * n * n - 15 * n) / 2;
    }
      
    // Driver Code
    static public void Main ()
    {
    int n = 6;
    Console.Write(n + "th Enneadecagonal number :");
      
    Console.WriteLine( nthEnneadecagonal(n));
    }
}
  
// This code is contributed by aj_36


PHP


输出 :

6th Enneadecagonal number :261

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