## Thursday, November 17, 2016

### n'th Pentagonal Number - GeeksforGeeks

n'th Pentagonal Number - GeeksforGeeks
Given an integer n, find the nth Pentagonal number. First three pentagonal numbers are 1, 5 and 12 (Please see below diagram).
The n'th pentagonal number Pn is the number of distinct dots in a pattern of dots consisting of the outlines of regular pentagons with sides up to n dots, when the pentagons are overlaid so that they share one vertex

In general, a polygonal number (triangular number, square number, etc) is a number represented as dots or pebbles arranged in the shape of a regular polygon. The first few pentagonal numbers are: 1, 5, 12, etc.
If s is the number of sides in a polygon, the formula for the nth s-gonal number P (s, n) is
```nth s-gonal number P(s, n) = (s - 2)n(n-1)/2 + n

If we put s = 5, we get

n'th Pentagonal number Pn = 3*n*(n-1)/2 + n```
Examples:
Triangular number
Square number
Pentagonal Number
`    ``int` `pentagonalNum(``int` `n)`
`    ``{`
`        ``return` `(``3``*n*n - n)/``2``;`
`    ``}`