To find the nth heptagonal number, we can use the formula:
main.php15 chars2 lines
where Hn is the nth heptagonal number.
We can implement this formula in PHP as follows:
main.php113 chars7 lines
In the above code, we define a function heptagonal
that takes an integer argument n
and returns the nth heptagonal number using the formula. We then demonstrate the usage of this function by calling it with the argument 5 and outputting the result, which should be 95.
gistlibby LogSnag