To find the nth square number in Swift, you can use the following algorithm that involves basic math and iteration:
main.swift61 chars4 lines
This function takes an integer n
as input and returns the n
th square number. This is achieved by simply multiplying n
with itself.
For example, findNthSquareNumber(5)
would return 25
since the 5th square number is 25.
gistlibby LogSnag