# Decagonal Numbers

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 <bits/stdc++.h> ` `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; ` `} ` |

*chevron_right*

*filter_none*

## 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. ` |

*chevron_right*

*filter_none*

## 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)) ` |

*chevron_right*

*filter_none*

## 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. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find nth ` `// decagonal number ` ` ` `// Function to calculate ` `// decagonal number ` `function` `decagonal(` `$n` `) ` `{ ` ` ` ` ` `// Formula for finding nth ` ` ` `// decagonal number ` ` ` `return` `4 * ` `$n` `* ` `$n` `- 3 * ` `$n` `; ` `} ` ` ` `// Driver function ` `$n` `= 10; ` `echo` `$n` `, ` `"th decagonal number :"` `, ` ` ` `decagonal(` `$n` `); ` ` ` `// This code is contributed by ajit ` `?> ` |

*chevron_right*

*filter_none*

Output:

10th decagonal number : 370

## Recommended Posts:

- Centered decagonal number
- C program to find Decagonal Number
- Numbers less than N which are product of exactly two distinct prime numbers
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Count numbers which can be constructed using two numbers
- Count numbers which are divisible by all the numbers from 2 to 10
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Add two numbers using ++ and/or --
- Sum of first n even numbers
- Hailstone Numbers
- Tribonacci Numbers
- Taxicab Numbers

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.