To solve square root in Swift, you can use the sqrt
function provided by the Swift's standard library.
Here's an example code snippet to find the square root of a number:
main.swift81 chars4 lines
The sqrt
function takes a single argument of type Double and returns its square root as a Double value.
If you want to calculate square root of a negative number, it'll return NaN (not a number).
main.swift118 chars4 lines
gistlibby LogSnag