# Icosagonal number

Given a number n, the task is to find the nth Icosagonal number.

An Icosagonal number is the 20-gon is a twenty-sided polygon. The number derived from the figurative class. There are different pattern series number in this number. The dots are countable, arrange in a specific way of position and create a diagram. All the dots have a common dots points, all others dots are connected to this points and except this common point the dots connected to their i-th dots with their respective successive layer.

**Examples :**

Input : 3

Output :57

Input :8

Output :512

Formula for nth icosagonal number:

## C++

`// C++ program to find ` `// nth Icosagonal number ` `#include <bits/stdc++.h> ` `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; ` `} ` |

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find ` `// nth Icosagonal number ` ` ` `// Function to calculate ` `// Icosagonal number ` `function` `icosagonal_poly(` `$n` `) ` `{ ` ` ` `// Formula for finding ` ` ` `// nth Icosagonal number ` ` ` `return` `(18 * ` `$n` `* ` ` ` `$n` `- 16 * ` `$n` `) / 2; ` `} ` ` ` `// Driver Code ` `$n` `= 7; ` `echo` `$n` `, ` `"th Icosagonal number :"` `, ` ` ` `icosagonal_poly(` `$n` `); ` ` ` `// This code is contributed by ajit ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

7th Icosagonal number :385

Reference: https://en.wikipedia.org/wiki/Polygonal_number

## Recommended Posts:

- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find minimum number to be divided to make a number a perfect square
- Number of times the largest perfect square number can be subtracted from N
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Given number of matches played, find number of teams in tournament
- Number of ways to split a binary number such that every part is divisible by 2
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Querying maximum number of divisors that a number in a given range has
- Find count of digits in a number that divide the number
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Count the number of operations required to reduce the given number
- Build Lowest Number by Removing n digits from a given number
- Count number of ways to divide a number in 4 parts
- Minimum number of given powers of 2 required to represent a number

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.