Go program to Find Volume and Surface Area of a Cylinder

Write a Go program to Find Volume and Surface Area of a Cylinder. The math formula to calculate the cylinder volume, surface area, and lateral surface area are

  • Surface Area of a Cylinder = 2πr² + 2πrh (r = radius and h = cylinder height).
  • Cylinder Volume = πr²h
  • The Lateral Surface Area of a Cylinder = 2πrh
  • Cylinder Top Or Bottom Surface Area = πr²
package main

import (
    "fmt"
    "math"
)

func main() {

    var cyRadius, cyHeight, cySA, cyVol, cyL, cyT float32

    fmt.Print("Enter the Cylinder Radius = ")
    fmt.Scanln(&cyRadius)

    fmt.Print("Enter the Cylinder Height = ")
    fmt.Scanln(&cyHeight)

    cySA = 2 * math.Pi * cyRadius * (cyRadius + cyHeight)
    cyVol = math.Pi * cyRadius * cyRadius * cyHeight
    cyL = 2 * math.Pi * cyRadius * cyHeight
    cyT = math.Pi * cyRadius * cyRadius

    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)
Go program to Find Volume and Surface Area of a Cylinder

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.