给您一个数字n,任务是找到第n个十进制数。十进制数是将三角形和正方形数的概念扩展到十进制(十边形多边形)的图形数。第n个十进制数计算n个嵌套的十进制图案中的点数,它们全部共享一个公共角,其中该模式中的第i个十进制具有由i个点组成的边,这些点相互间隔一个单位。
例子:
Input : n = 3
Output : 27
Input : n = 7
Output : 175
第n个十进制数由以下公式给出
(4n 2 – 3n) 。
C++
// C++ program to find nth decagonal number
#include
using namespace std;
// Function to calculate decagonal number
int decagonal(int n)
{
// Formula for finding nth decagonal number
return 4 * n * n - 3 * n;
}
// Driver function
int main()
{
int n = 10;
cout << n << "th decagonal number :" << decagonal(n);
return 0;
}
Java
// JAVA Code for Decagonal Numbers
import java.util.*;
class GFG {
// Function to calculate
// decagonal number
static int decagonal(int n)
{
// Formula for finding nth
// decagonal number
return 4 * n * n - 3 * n;
}
/* Driver function */
public static void main(String[] args)
{
int n = 10;
System.out.println(n + "th decagonal number :"
+ decagonal(n));
}
}
// This code is contributed by Arnav Kr. Mandal.
Python
# Python program to find nth decagonal number
def decagonal(n):
return 4 * n * n - 3 * n
# Driver code
n = 10
print(n, "th decagonal number :", decagonal(n))
C#
// C# Code for Decagonal Numbers
using System;
class GFG {
// Function to calculate
// decagonal number
static int decagonal(int n)
{
// Formula for finding nth
// decagonal number
return 4 * n * n - 3 * n;
}
// Driver Code
public static void Main()
{
int n = 10;
Console.Write(n + "th decagonal number : "
+ decagonal(n));
}
}
// This code is contributed by vt_m.
PHP
Javascript
输出:
10th decagonal number : 370