这个 Go 程序使用用户给定的值来查找数字的平方根,它调用了内置的 math.Sqrt 函数。
package main
import (
"fmt"
"math"
)
func main() {
var sqrtnum, sqrtOut float64
fmt.Print("\nEnter the Number to find Square Root = ")
fmt.Scanln(&sqrtnum)
sqrtOut = math.Sqrt(sqrtnum)
fmt.Println("\nThe Square of a Given Number = ", sqrtOut)
}
SureshMac:GoExamples suresh$ go run squareroot1.go
Enter the Number to find Square Root = 64
The Square of a Given Number = 8
SureshMac:GoExamples suresh$ go run squareroot1.go
Enter the Number to find Square Root = 82
The Square of a Given Number = 9.055385138137417
Golang 程序查找数字的平方根
这个 golang 程序 使用 math.Pow 函数来计算给定数字的平方根。
package main
import (
"fmt"
"math"
)
func main() {
var sqrtnum, sqrtOut float64
fmt.Print("\nEnter the Number to find Square Root = ")
fmt.Scanln(&sqrtnum)
sqrtOut = math.Pow(sqrtnum, 0.5)
fmt.Println("\nThe Square of a Given Number = ", sqrtOut)
}
