📜  余角数

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

给定数字n,任务是找到第n个二十边形数。
二十边形是20边形,二十面是多边形。从象征性类派生的数字。此编号中有不同的图案系列编号。点是可数的,以特定的位置排列并创建图表。所有的点都有一个共同的点,所有其他的点都连接到该点,除了这个共同的点,它们的第i个点通过各自的连续层连接。

例子 :

二十边形数

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

  \begin{math}  Ig_{n}=((18n^2)-16n)/2 \end{math}

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


Java
// Java program to find
// nth Icosagonal number
  
import java.io.*;
  
class GFG {
      
// Function to calculate Icosagonal number
  
static int icosagonal_poly(int n)
{
    // Formula for finding
    // nth Icosagonal number
    return (18 * n * n - 16 * n) / 2;
}
  
// Drivers code
      
    public static void main (String[] args) {
     
    int n = 7;
      
    System.out.print (n + "th Icosagonal number :");
    System.out.println(icosagonal_poly(n));
    }
}
// This code is contributed by aj_36


Python 3
# Python 3 program to find 
# nth Icosagonal number
  
# Function to calculate
# Icosagonal number
def icosagonal_poly(n) :
      
    # Formula for finding
    # nth Icosagonal number
    return (18 * n * n - 
            16 * n) // 2
  
# Driver Code
if __name__ == '__main__' :
    n = 7
    print(n,"th Icosagonal number : ", 
                   icosagonal_poly(n))
  
# This code is contributed m_kit


C#
// C# program to find
// nth Icosagonal number
using System;
  
class GFG
{
  
// Function to calculate
// Icosagonal number
static int icosagonal_poly(int n)
{
    // Formula for finding
    // nth Icosagonal number
    return (18 * n * n - 
            16 * n) / 2;
}
  
// Driver code
static public void Main ()
{
      
int n = 7;
  
Console.Write(n + "th Icosagonal " +
                        "number :");
Console.WriteLine(icosagonal_poly(n));
}
}
  
// This code is contributed by ajit


PHP


输出 :

7th Icosagonal number :385

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