此 Go 程序用于计算球体的体积和表面积,用户可以输入球体的半径。然后,它将使用数学公式计算表面积,其中 r 是半径。
- 球体表面积 = 4πr²
- 球体半径 = √表面积 / 4π
- 球体体积 = 4πr³
package main
import "fmt"
func main() {
var spRadius, spSA, spVolume
fmt.Print("Enter the Sphere Radius= ")
fmt.Scanln(&spRadius)
spSA = 4 * 3.14 * spRadius * spRadius
spVolume = (4.0/3) * 3.14 * spRadius * spRadius * spRadius
fmt.Println("The Surface Area of a Sphere = ", spSA)
fmt.Println("The Volume of a Sphere = ", spVolume)
}
