GO Program to find volume and surface area of a cylinder

How to find the volume and surface area of a cylinder

Here we are explaining how to find the volume and surface area of a cylinder in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.

Surface Area of a Cylinder =  2πr² + 2πrh 

Cylinder Volume =  πr²h 

The Lateral Surface Area of a Cylinder = 2πrh 

Cylinder Top Or Bottom Surface Area = πr² 

Where r is the radius of the cylinder and h is the cylinder height

 

How to find volume and surface area of a cylinder in GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to find the volume and surface area of a cylinder in the Go language. Here variable cyRa,cyHt holds the radius and height of the cylinder. Other variables cySA, cyVol, cyL, cyT are used as the result variable of surface area, volume, lateral surface area, Top or bottom surface area. Use the mathematical functions for the calculation. Volume is found by using  πr²h and surface area by using 2πr² + 2πrh. Finally print the results. Given below are the steps which are used in the Go program. 

ALGORITHM

STEP 1: Import the package fmt, math

STEP 2: Start function main()

STEP 3: Declare the variable cyRa,cyHt,cySA, cyVol, cyL, cyT

STEP 4: Read the radius and height of the cylinder cyRa,cyHt

STEP 5: Calculate the surface area by using 2πr² + 2πrh

STEP 6: Calculate the volume by using πr²h

STEP 7: Calculate the lateral surface area by using 2πrh

STEP 8: Calculate the top or bottom surface area by using πr²

STEP 9Print the cySA, cyVol, cyL, cyT using fmt.Println()

 

GO Source Code

                                          package main

import (
    "fmt"
    "math"
)

func main() {

    var cyRa, cyHt, cySA, cyVol, cyL, cyT float32

    fmt.Print("Enter the radius  of Cylinder = ")
    fmt.Scanln(&cyRa;)
    fmt.Print("Enter the height Cylinder = ")
    fmt.Scanln(&cyHt;)

    cySA = 2 * math.Pi * cyRad * (cyRa+ cyHt)
    cyVol = math.Pi * cyRa * cyRa * cyHt
    cyL = 2 * math.Pi * cyRa * cyHt
    cyT = math.Pi * cyRa * cyRa

    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)
    fmt.Println("Top or bottom surface area of a Cylinder    = ", cyT)

                                      

OUTPUT

Enter the radius of Cylinder = 5
Enter the height Cylinder = 9
The volume of a Cylinder                = 706.8583
The surface area of a Cylinder            = 439.823
The lateral surface area of a Cylinder    = 282.7433
Top or bottom surface area of a Cylinder    = 78.5398