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
+6.1k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+22.9k Golang : Test file read write permission example
+5.2k Golang : Calculate half life decay example
+5.6k Golang : Detect words using using consecutive letters in a given string
+5.7k Golang : Find change in a combination of coins example
+11.3k Golang : How to flush a channel before the end of program?
+7.8k Golang Hello World Example
+10.7k Golang : Get currencies exchange rates example
+15.5k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+28.5k Golang : Read, Write(Create) and Delete Cookie example
+13.5k Golang : Query string with space symbol %20 in between