main.swift101 chars5 linesThe pentagonalNumber function takes an integer n as input and calculates the nth pentagonal number using the formula P_n = n(3n - 1) / 2. The result is then returned as an integer.
For example, to find the 7th pentagonal number, we can call the function like this:
main.swift61 chars3 linesThe 7th pentagonal number is 92.
gistlibby LogSnag