GO Program to find volume and surface area of a cube

How to find the volume and surface area of a cube

Here we are explaining how to find the volume and surface area of a cube 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 Cube =  6l² 

Cube Volume =  l * l * l 

The Lateral Surface Area of a Cube = 4 * (l * l) 

Where l is length of any side of a Cube

 

How to find volume and surface area of a cube 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 cube in the Go language. Here variable len holds the length of the cube. Other variables SA, Vol, LA are used as the result variable of surface area, volume, lateral surface area. Use the mathematical functions for the calculation. Volume is found by using l * l * l and surface area by using 6l². Finally print the results. Given below are the steps which are used in the Go program. 

ALGORITHM

STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Declare the variable len,SA, Vol, LA

STEP 4: Read the length of any side of cube len

STEP 5: Calculate the surface area by using 6l²

STEP 6: Calculate the volume by using l * l * l

STEP 7: Calculate the lateral surface area by using 4 * (l * l)

STEP 8: Print the SA, Vol, LA using fmt.Println()

 

GO Source Code

                                          package main

import "fmt"

func main() {

    var len, SA, Vol, LA float32

    fmt.Print("Enter the length of any side of a cube = ")
    fmt.Scanln(&len;)

    SA = 6 * (len * len)
    Vol = len * len * len
    LA = 4 * (len * len)

    fmt.Println("\nThe volume of a cube            = ", Vol)
    fmt.Println("The surface area of a cube      = ", SA)
    fmt.Println("Lateral surface area of a cube  = ", LA)
}

                                      

OUTPUT

Enter the length of any side of a cube = 7
The volume of a cube            = 343
The surface area of a cube      = 294
Lateral surface area of a cube  = 196