GO Program to find volume and surface area of a sphere

How to find the volume and surface area of a sphere

Here we are explaining how to find the volume and surface area of a sphere 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.

Sphere Surface Area =  4πr² 

Sphere Volume =  4πr³ 

Where π value is 3.14 and r is the radius of the sphere


How to find volume and surface area of a sphere 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 sphere in the Go language. Here variable spRa holds the radius of the sphere. Other variables spAr, spVol is used as the result variable of surface area and volume. Use the mathematical functions for the calculation. Volume is found by using  4πr³ and surface area by using 4πr². Finally print the results. Given below are the steps which are used in the Go program. 


STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Declare the variable spRa, spAr, spVol

STEP 4: Read the radius of the sphere spRa 

STEP 5: Calculate the surface area by using 4πr²

STEP 6: Calculate the volume by using 4πr³

STEP 7:Print the spAr and spVol using fmt.Println()


GO Source Code

                                          package main
import "fmt"

func main() {
    var spRa, spAr, spVol
    fmt.Print("Enter the radius of Sphere = ")

    spAr = 4 * 3.14 * spRa * spRa
    spVol = (4.0/3) * 3.14 * spRa * spRa * spRa

    fmt.Println("The surface area of a sphere  = ", spAr)
    fmt.Println("The volume of a sphere  = ", spVol)


Enter the radius of Sphere = 8
The surface area of a sphere  = 803.84 
The volume of a sphere  = 2143.573333