package main
import (
"fmt"
"math"
)
func sqrt(x float64) string {
// just like any other programming language's
// if statement
if x < 0 {
return sqrt(-x) + "i"
}
// quick way to convert the value to a string
return fmt.Sprint(math.Sqrt(x))
}
func main() {
fmt.Println(sqrt(2), sqrt(-4))
}
To embed this program on your website, copy the following code and paste it into your website's HTML: