To find the nth decagonal number in Swift, you can use the formula:
n * (9*n - 7)
Here is a function that implements this formula:
main.swift67 chars4 lines
You can call this function with the desired value of n:
main.swift41 chars2 lines
This will output the 5th decagonal number, which is 145.
gistlibby LogSnag