# Nonagonal number

A nonagonal number is a figurate number that extends the concept of triangular and square numbers to the nonagon. Specifically, the nth nonagonal numbers counts the number of dots in a pattern of n nested nonagons (9 sided polygons), all sharing a common corner, where the ith nonagon in the pattern has sides made of i dots spaced one unit apart from each other.

Examples :

```Input : n = 10
n (7n - 5) / 2
10 * (7 * 10 - 5) / 2
10 * 65 / 2 = 325
Output :325

Input : 15
Output :750
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

The nth nonagonal number is given by the formula: n (7n – 5) / 2.

## C++

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

## Java

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

## Python3

 `# Python 3 Program to find ` `# nth nonagonal number. ` ` `  `# Function to find nth ` `# nonagonal number. ` `def` `Nonagonal(n): ` `  `  `    ``# Formula to find nth  ` `    ``# nonagonal number. ` `    ``return` `int``(n ``*` `(``7` `*` `n ``-` `5``) ``/` `2``)  ` `  `  `n ``=` `10`   `print``(Nonagonal(n))  ` ` `  `# This code is contributed bt ` `# Smitha Dinesh Semwal `

## C#

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

## PHP

 ` `

Output :

```325
```

Given a number n, find nonagonal number series till n terms .

## C++

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

## Java

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

## Python3

 `# Python 3 Program find first ` `# n nonagonal number. ` ` `  `# Function to find nonagonal ` `# number series. ` `def` `Nonagonal(n): ` `  `  `    ``for` `i ``in` `range``(``1``, n``+``1``):   ` `        ``print``(``int``(i ``*` `(``7` `*` `i ``-` `5``) ``/` `2``),end``=``" "``)  ` `     `  `# driver Function      ` `n ``=` `10`  `Nonagonal(n)  ` `     `  `# This code is contributed by ` `# Smitha Dinesh Semwal `

## C#

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

## PHP

 ` `

Output :

```1 9 24 46 75 111 154 204 261 325
```

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, jit_t

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.