To find the surface area of a rectangular prism in Go, we need to use the formula:
Surface Area = 2lw + 2lh + 2wh
Where l, w, and h are the length, width, and height of the rectangular prism.
Here's a code snippet in Go that calculates the surface area of a rectangular prism by taking user input for its dimensions:
main.go312 chars14 lines
In this code, we first declare four variables - l
, w
, h
, and surfaceArea
. We then use the fmt.Scanln
function to take user input for the length, width, and height.
We calculate the surface area using the formula mentioned earlier, and assign the result to the surfaceArea
variable.
Finally, we use the fmt.Printf
function to print the result with two decimal places.
gistlibby LogSnag