How to calculate the square root of a number in Go?

In Go, you can calculate the square root of a number using the math.Sqrt function from the math package. Here is an example:

package main import ( "fmt" "math" ) func main() { number := 16.0 sqrt := math.Sqrt(number) fmt.Printf("Square root of %.2f is %.2f\n", number, sqrt) }

In this example, we calculate the square root of the number 16.0 using math.Sqrt and store the result in the variable sqrt. The output will be:

Square root of 16.00 is 4.00

Note that the math.Sqrt function takes and returns a float64, so make sure to use appropriate types. Additionally, make sure to import the math package before using the math.Sqrt function.