编写一个 Go 程序来查找长方体的体积和表面积。长方体的体积、表面积和侧面积的数学公式为:
- 长方体总表面积 = 2lw + 2lh + 2wh,其中 l = 长度,w = 宽度,h = 高度
- 长方体的体积 = lbh
- 长方体的侧面积 = 2h (l + w)
package main
import "fmt"
func main() {
var cublen, cubWidth, cubHeight, cubSA, cubVolume, cubLA float32
fmt.Print("Enter the Length of a Cuboid = ")
fmt.Scanln(&cublen)
fmt.Print("Enter the Width of a Cuboid = ")
fmt.Scanln(&cubWidth)
fmt.Print("Enter the Height of a Cuboid = ")
fmt.Scanln(&cubHeight)
cubSA = 2 * (cublen*cubWidth + cublen*cubHeight + cubWidth*cubHeight)
cubVolume = cublen * cubWidth * cubHeight
cubLA = 2 * cubHeight * (cublen + cubWidth)
fmt.Println("\nThe Volume of a Cuboid = ", cubVolume)
fmt.Println("The Surface Area of a Cuboid = ", cubSA)
fmt.Println("Lateral Surface Area of a Cuboid = ", cubLA)
}
