find the nth square number in swift

To find the nth square number in Swift, you can use the following algorithm that involves basic math and iteration:

main.swift
func findNthSquareNumber(_ n: Int) -> Int {
  return n * n
}
61 chars
4 lines

This function takes an integer n as input and returns the nth 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