Menu Close

Go – How to get the square root of number in go

Here, We will learn how to get the square root of number in go. We can get it by using Sqrt() function in math package in go golang.

Function prototype:

func Sqrt(x float64) float64

Return value:

Sqrt() function in math package returns 
the square root of number.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Sqrt(27)
  fmt.Println(no)

  no = math.Sqrt(144)
  fmt.Println(no)

  no = math.Sqrt(25)
  fmt.Println(no)

  no = math.Sqrt(2.9)
  fmt.Println(no)

  no = math.Sqrt(0)
  fmt.Println(no)
}

Output:

5.196152422706632
12
5
1.70293863659264
0

To learn more about golang, Please refer given below link:

https://techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *