find the surface area of a cylinder in go

To find the surface area of a cylinder in Go, we can use the formula:

2πr² + 2πrh

where r is the radius of the base of the cylinder and h is the height of the cylinder.

Here's the Go code to calculate the surface area of a cylinder:

main.go
package main

import (
    "fmt"
    "math"
)

func main() {
    var radius float64 = 5
    var height float64 = 10

    // calculate the surface area
    surfaceArea := 2*math.Pi*math.Pow(radius, 2) + 2*math.Pi*radius*height

    // print the surface area
    fmt.Println("Surface area of cylinder:", surfaceArea)
}
317 chars
18 lines

In this example, we've set the radius to 5 and the height to 10. You can change these values to match the dimensions of the cylinder you're working with. The math.Pi function is from the built-in math package in Go.

gistlibby LogSnag