Related Articles

# Dodecagonal number

• Last Updated : 19 Jul, 2021

Given a number n, find the nth Dodecagonal number.Dodecagonal numbers represent Dodecagonal (A polygon with 12 sides).
Some of the Dodecagonal numbers are:
1, 12, 33, 64, 105, 156, 217, 288, 369, 460, 561, 672, 793, 924………………………..
Examples :

```Input : n = 4
Output : 64

Input : n = 9
Output : 369```

Formula of nth Term of Dodecagonal number :

`n-th Dodecagonal number = 5n2 - 4n`

Below is the implementation for nth Dodecagonal Number:

## C++

 `// CPP Program to find the``// nth Dodecagonal number``#include ``using` `namespace` `std;` `// function for Dodecagonal``// number``int` `Dodecagonal_number(``int` `n)``{``    ``// formula for find Dodecagonal``    ``// nth term``    ``return` `5 * n * n - 4 * n;``}` `// Driver Code``int` `main()``{` `    ``int` `n = 7;``    ``cout << Dodecagonal_number(n) << endl;` `    ``n = 12;``    ``cout << Dodecagonal_number(n) << endl;` `    ``return` `0;``}`

## Java

 `// Java program to find the``// nth Dodecagonal number``import` `java.util.*;` `class` `GFG``{` `    ``// function for``    ``// Dodecagonal number``    ``static` `int` `Dodecagonal_number(``int` `n)``    ``{``        ``// formula for find``        ``// Dodecagonal nth term``        ``return` `5` `* n * n - ``4` `* n;``    ``}``    ` `    ``// Driver Code``    ``public` `static` `void` `main(String[] args)``    ``{` `    ``int` `n = ``7``;``    ``System.out.println(Dodecagonal_number(n));` `    ``n = ``12``;``    ``System.out.println(Dodecagonal_number(n));` `    ``}``}` `// This code is contributed by Anuj_67`

## Python3

 `# Python program to find``# nth Dodecagonal number` `# Function to calculate``# Dodecagonal number``def` `Dodecagonal_number(n):` `    ``# Formula to calculate nth``    ``# Dodecagonal number``    ` `    ``return`  `5` `*` `n ``*` `n ``-` `4` `*` `n` `# Driver Code``n ``=` `7``print``(Dodecagonal_number(n))` `n ``=` `12``print``(Dodecagonal_number(n))``                    ` `# This code is contributed by aj_36.`

## C#

 `// C# program to find the nth Dodecagonal``// number``using` `System;` `class` `GFG {` `    ``// function for Dodecagonal``    ``// number``    ``static` `int` `Dodecagonal_number(``int` `n)``    ``{``        ``// formula for find Dodecagonal``        ``// nth term``        ``return` `5 * n * n - 4 * n;``    ``}``    ` `    ``// Driver Code``    ``static` `void` `Main()``    ``{``    ` `        ``int` `n = 7;``        ``Console.WriteLine(Dodecagonal_number(n));``    ` `        ``n = 12;``        ``Console.WriteLine(Dodecagonal_number(n));``    ` `    ``}``}` `// This code is contributed by Anuj_67`

## PHP

 ``

## Javascript

 ``
Output :

```217
672```

Time Complexity: O(1)
Auxiliary Space: O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up