为了更好地理解这个示例,我们始终建议您学习下面列出的 Golang 编程 的基础主题
圆柱体的体积是圆柱体的密度,或者说可以浸入其中的任何材料的数量。圆柱体的体积由以下公式给出:
圆柱体体积 = πr²h
圆柱体的表面积定义为圆柱体曲面和两个圆形底面面积之和。
圆柱体的表面积 = 曲面 + 圆形底面面积
圆柱体表面积 = 2πr² + 2πrh
物体的侧面积等于物体的表面积减去物体底面的面积。
圆柱体的侧面积 = 2πrh
圆柱体顶部或底部表面积 = πr²
其中 r 是圆柱体的半径,h 是圆柱体的高度
--这里我们将展示如何在 Go 语言中查找圆柱体的体积和表面积。这里变量 Rds, Hgt 存储圆柱体的半径和高度。其他变量 SA, Vol, LSA, TA 用作表面积、体积、侧面积、顶部或底部表面积的结果变量。使用数学函数进行计算。体积通过 πr²h 找到,表面积通过 2πr² + 2πrh 找到。最后打印结果。下面是 Go 程序中使用的步骤:
步骤 1:导入 fmt, math 包
第二步:启动 main() 函数
步骤 3:声明变量 Rds, Hgt, SA, Vol, LSA, TA
步骤 4:读取圆柱体的半径和高度 Rds, Hgt
步骤 5:使用 2πr² + 2πrh 计算表面积
步骤 6:使用 πr²h 计算体积
步骤 7:使用 2πrh 计算侧面积
步骤 8:使用 πr² 计算顶部或底部表面积
步骤 9: 使用 fmt.Println() 打印 SA, Vol, LSA, TA
package main
import (
"fmt"
"math"
)
func main() {
var cyRa, cyHt, cySA, cyVol, cyL, cyT float32
fmt.Print("Enter the radius of Cylinder = ")
fmt.Scanln(&cyRa;)
fmt.Print("Enter the height Cylinder = ")
fmt.Scanln(&cyHt;)
cySA = 2 * math.Pi * cyRad * (cyRa+ cyHt)
cyVol = math.Pi * cyRa * cyRa * cyHt
cyL = 2 * math.Pi * cyRa * cyHt
cyT = math.Pi * cyRa * cyRa
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)
fmt.Println("Top or bottom surface area of a Cylinder = ", cyT)
Enter the radius of Cylinder = 5 Enter the height Cylinder = 9 The volume of a Cylinder = 706.8583 The surface area of a Cylinder = 439.823 The lateral surface area of a Cylinder = 282.7433 Top or bottom surface area of a Cylinder = 78.5398