Golang : Math pow(the power of x^y) example
No programming language will be complete without the power of
math function. This tutorial is a simple example on how to use math.Pow()
function.
In Math
2^5 = 2x2x2x2x2 =32
In Golang
Math.pow(2, 5)
In code :
package main
import (
"fmt"
"math"
)
func main() {
result := math.Pow(2, 5)
fmt.Println(" 2 power of 5 is : ", result)
x := 10.5
y := 5
floatResult := math.Pow(x, float64(y)) //type cast int to float64
fmt.Printf(" %.02f power of %d is : %.02f \n", x, y, floatResult)
}
2 power of 5 is : 32
10.50 power of 5 is : 127628.16
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.6k Golang : How to generate QR codes?
+7.8k Golang : Get final balance from bit coin address example
+39.8k Golang : How to check if a string contains another sub-string?
+4.6k Clean up Visual Studio For Mac installation failed disk full problem
+7.7k Android Studio : Indicate progression with ProgressBar example
+9.7k Golang : Command line file upload program to server example
+5.4k CodeIgniter : form input set_value cause " to become & quot
+4.4k Unix/Linux : How to archive and compress entire directory ?
+22.4k Golang : Check if element exist in map
+31.3k Golang : How to check if a date is within certain range?
+12.9k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example