Go 程序:计算圆锥的体积和表面积

编写一个 Go 程序来计算圆锥的体积和表面积。计算圆锥体积、表面积和侧面积的数学公式是:

  • 圆锥表面积 = πrl + πr² (l = 斜高,r = 半径)
  • 圆锥体积 = 1/3 πr²h ( h = 圆锥高)
  • 圆锥的侧面积 = πrl
package main

import (
    "fmt"
    "math"
)

func main() {

    var cnRadius, cnHeight, cnSA, cnVol, cnLSA, cnLen float64

    fmt.Print("Enter the Cone Radius = ")
    fmt.Scanln(&cnRadius)

    fmt.Print("Enter the Cone Height = ")
    fmt.Scanln(&cnHeight)

    cnLen = math.Sqrt(cnRadius*cnRadius + cnHeight*cnHeight)
    cnSA = math.Pi * cnRadius * (cnRadius + cnLen)
    cnVol = (1.0 / 3) * math.Pi * cnRadius * cnRadius * cnHeight
    cnLSA = math.Pi * cnRadius * cnLen

    fmt.Println("The Length of a Cone Side (Slant)  = ", cnLen)
    fmt.Println("The Volume of a Cone               = ", cnVol)
    fmt.Println("The Surface Area of a Cone         = ", cnSA)
    fmt.Println("The Lateral Surface Area of a Cone = ", cnLSA)
}
Go program to Find Volume and Surface Area of a Cone