# Program for centered nonagonal number

Centered nonagonal number is a centered figurate number that represents a nonagon with a dot in the center and all other dots surrounding to the center dot in successive nonagonal layers.

The centered nonagonal number for n is given by
Centered nonagonal number = (3 * n – 2) * (3 * n – 1) / 2;
https://en.wikipedia.org/wiki/Centered_nonagonal_number

Examples :

```Input : n = 10
Output : 406

Input : n = 8
Output : 253
```

## C++

 `// CPP Program to find ` `// nth centered nonagonal number. ` `#include ` `using` `namespace` `std; ` ` `  `// Function to find nth ` `// centered nonagonal number. ` `int` `centeredNonagonal(``int` `n) ` `{ ` `    ``// Formula to find nth centered ` `    ``// nonagonal number. ` `    ``return` `(3 * n - 2) * (3 * n - 1) / 2; ` `} ` ` `  `// Driver function. ` `int` `main() ` `{ ` `    ``int` `n = 10; ` `    ``cout << centeredNonagonal(n); ` `    ``return` `0; ` `} `

## Java

 `// Java Program to find ` `// nth centered nonagonal number. ` `import` `java.io.*; ` ` `  `class` `GFG { ` `     `  `    ``// Function to find nth ` `    ``// centered nonagonal number. ` `    ``static` `int` `centeredNonagonal(``int` `n) ` `    ``{ ` `        ``// Formula to find nth centered ` `        ``// nonagonal number. ` `        ``return` `(``3` `* n - ``2``) * (``3` `* n - ``1``) / ``2``; ` `    ``} ` `     `  `    ``// Driver function. ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``int` `n = ``10``; ` `        ``System.out.println(centeredNonagonal(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by Nikita Tiwari. `

## Python3

 `# Python 3 Program to find ` `# nth centered nonagonal number. ` ` `  `# Function to find nth ` `# centered nonagonal number ` `def` `centeredNonagonal(n) : ` `     `  `    ``# Formula to find nth centered ` `    ``# nonagonal number. ` `    ``return` `(``3` `*` `n ``-` `2``) ``*` `(``3` `*` `n ``-` `1``) ``/``/` `2` `     `  `# Driver function. ` `n ``=` `10` `print``(centeredNonagonal(n)) ` ` `  `# This code is contributed  ` `# by Nikita Tiwari. `

## C#

 `// C# Program to find nth ` `// centered nonagonal number. ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``// Function to find nth ` `    ``// centered nonagonal number. ` `    ``static` `int` `centeredNonagonal(``int` `n) ` `    ``{ ` `        ``// Formula to find nth centered ` `        ``// nonagonal number. ` `        ``return` `(3 * n - 2) * (3 * n - 1) / 2; ` `    ``} ` `     `  `    ``// Driver function. ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``int` `n = 10; ` `        ``Console.Write(centeredNonagonal(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by vt_m. `

## PHP

 ` `

Output:

```406
```

Given a number n, find centered nonagonal number series till n.
We can also find the centered nonagonal number series. centered nonagonal number series contains the points on centered nonagonal.
centered nonagonal number : 1, 10, 28, 55, 91, 136, 190, 253, 325, 406, 496, 595, 703, 820, 946 . . .

## C++

 `// CPP Program find first ` `// n centered nonagonal number. ` `#include ` `using` `namespace` `std; ` ` `  `// Function to find centered ` `// nonagonal number series. ` `int` `centeredNonagonal(``int` `n) ` `{ ` `    ``for` `(``int` `i = 1; i <= n; i++) { ` `        ``cout << (3 * i - 2) * (3 * i - 1) / 2; ` `        ``cout << ``" "``; ` `    ``} ` `} ` ` `  `// Driver function. ` `int` `main() ` `{ ` `    ``int` `n = 10; ` `    ``centeredNonagonal(n); ` `    ``return` `0; ` `} `

## Java

 `// Java Program find first ` `// n centered nonagonal number. ` `import` `java.io.*; ` ` `  `class` `GFG { ` `     `  `    ``// Function to find centered ` `    ``// nonagonal number series. ` `    ``static` `void` `centeredNonagonal(``int` `n) ` `    ``{ ` `        ``for` `(``int` `i = ``1``; i <= n; i++)  ` `        ``{ ` `            ``System.out.print((``3` `* i - ``2``) *  ` `                             ``(``3` `* i - ``1``) / ``2``); ` `            ``System.out.print(``" "``); ` `        ``} ` `    ``} ` ` `  `    ``// Driver function. ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``int` `n = ``10``; ` `        ``centeredNonagonal(n); ` `    ``} ` `} ` ` `  `// This code is contributed  ` `// by Nikita Tiwari. `

## Python3

 `# Python3 Program find first ` `# n centered nonagonal number ` ` `  `# Function to find centered ` `# nonagonal number series ` `def` `centeredNonagonal(n) : ` `     `  `    ``for` `i ``in` `range``(``1``, n ``+` `1``) : ` `        ``print``( (``3` `*` `i ``-` `2``) ``*` `(``3` `*` `i ``-` `1``) ``/``/` `2``, end``=``" "``) ` `         `  ` `  `# Driver function ` `n ``=` `10` `centeredNonagonal(n) ` ` `  `# This code is contributed by Nikita Tiwari `

## C#

 `// C# Program find first ` `// n centered nonagonal number. ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``// Function to find centered ` `    ``// nonagonal number series. ` `    ``static` `void` `centeredNonagonal(``int` `n) ` `    ``{ ` `        ``for` `(``int` `i = 1; i <= n; i++)  ` `        ``{ ` `            ``Console.Write((3 * i - 2) *  ` `                            ``(3 * i - 1) / 2); ` `                             `  `            ``Console.Write(``" "``); ` `        ``} ` `    ``} ` ` `  `    ``// Driver function. ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``int` `n = 10; ` `        ``centeredNonagonal(n); ` `    ``} ` `} ` ` `  `// This code is contributed by ` `// by vt_m. `

## PHP

 ` `

Output :

```1  10  28  55  91  136  190  253  325  406
```

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.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Improved By : vt_m