Go 程序:查找圆柱体的体积和表面积

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

  • 圆柱体表面积 = 2πr² + 2πrh(r = 半径,h = 圆柱体高度)。
  • 圆柱体体积 = πr²h
  • 圆柱体侧面积 = 2πrh
  • 圆柱体顶部或底部表面积 = πr²
package main

import (
    "fmt"
    "math"
)

func main() {

    var cyRadius, cyHeight, cySA, cyVol, cyL, cyT float32

    fmt.Print("Enter the Cylinder Radius = ")
    fmt.Scanln(&cyRadius)

    fmt.Print("Enter the Cylinder Height = ")
    fmt.Scanln(&cyHeight)

    cySA = 2 * math.Pi * cyRadius * (cyRadius + cyHeight)
    cyVol = math.Pi * cyRadius * cyRadius * cyHeight
    cyL = 2 * math.Pi * cyRadius * cyHeight
    cyT = math.Pi * cyRadius * cyRadius

    fmt.Println("\nThe Volume of a Cylinder                = ", cyVol)
    fmt.Println("The Surface Area of a Cylinder            = ", cySA)
    fmt.Println("The Lateral Surface Area of a Cylinder    = ", cyL)
Go program to Find Volume and Surface Area of a Cylinder