GO Program to find square root of a number

How to find the square root of a number

Here we are explaining how to find the square root of a number 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.

 

How to find the square root of a number in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing to find the square root of a number in the Go language. Here variables num for holding the number for the square root check, and other variable sqrt, for holding the result. The square root of the number is found out by using math.Sqrt(num). Here we must include the header file math for using this built-in function. 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 num, sqrt

STEP 4: Read the number num using fmt.Scanfln()

STEP 5:Find the square root of a number num using math.Sqrt(num)

STEP 6: Save the result into the variable sqrt

STEP 7: Print the result using fmt.Println()

 

GO Source Code

                                          package main

import (
    "fmt"
    "math"
)

func main() {

    var num, sqrt float64

    fmt.Print("\nEnter the number to find Square root = ")
    fmt.Scanln(#)

    sqrt = math.Sqrt(num)

    fmt.Println("\nThe Square root of a number = ", sqrt)
}
                                      

OUTPUT

Enter the number to find Square root = 81

The Square root of a number  = 9