Related Articles
Decagonal Numbers
• Last Updated : 09 Apr, 2021

You are given a number n, the task is to find the nth Decagonal number. A decagonal number is a figurate number that extends the concept of triangular and square numbers to the decagon (a ten-sided polygon). The nth decagonal numbers counts the number of dots in a pattern of n nested decagons, all sharing a common corner, where the ith decagon in the pattern has sides made of i dots spaced one unit apart from each other.

Examples:

```Input : n = 3
Output : 27

Input : n = 7
Output : 175
```

The n-th decagonal number is given by the formula
(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

 ``

Output:

`10th decagonal number : 370`

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up