find the surface area of a cube in go

To find the surface area of a cube in Golang, we need to measure the length of one of its sides. Once we have that value, we can use the formula:

main.go
Surface Area = 6 * side * side
31 chars
2 lines

Here's the Golang code to calculate the surface area of a cube:

main.go
package main

import "fmt"

func main() {
    var side float64
    fmt.Print("Enter the length of one side of the cube: ")
    fmt.Scan(&side)

    surfaceArea := 6 * side * side
    fmt.Printf("The surface area of the cube is: %.2f", surfaceArea)
}
250 chars
13 lines

In this code, we first prompt the user to input the length of one side of the cube. We then calculate the surface area using the formula mentioned above and store the result in a variable called surfaceArea. Finally, we print the surface area, rounded to the nearest hundredth, using the Printf function.

related categories

gistlibby LogSnag