For a better understanding of this example, we always recommend you to learn the basic topics of Golang programming listed below:
The volume of the cylinder is the density of the cylinder or how much amount of any material can be immersed in it. Volume of cylinder is given by .
Cylinder Volume = πr²h
The surface area of a cylinder is defined as the sum of the curved surface and the area of two circular bases of the cylinder.
The surface area of cylinder = curved surface + area of circular base
Surface Area of a Cylinder = 2πr² + 2πrh
The lateral surface area of an object is equal to the surface area minus the area of the bases of the object.
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
--Here we are showing how to find the volume and surface area of a cylinder in the Go language. Here variable Rds, Hgt holds the radius and height of the cylinder. Other variables SA, Vol, LSA, TA 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.
STEP 1: Import the package fmt, math
STEP 2: Start function main()
STEP 3: Declare the variable Rds, Hgt, SA, Vol, LSA, TA
STEP 4: Read the radius and height of the cylinder Rds, Hgt
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 9: Print the SA, Vol, LSA, TA using fmt.Println()
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)
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