main.php130 chars7 lines
The function nth_hexagonal_number($n)
takes an integer $n
as input and returns the $n$th hexagonal number. The formula to calculate the $n$th hexagonal number is $n(2n-1)$.
In the example usage, nth_hexagonal_numbser(5)
returns the 5th hexagonal number, which is 61.
gistlibby LogSnag