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
+20.1k Golang : How to get struct tag and use field name to retrieve data?
+9.8k Golang : Sort and reverse sort a slice of integers
+6.9k Web : How to see your website from different countries?
+25.2k Golang : Storing cookies in http.CookieJar example
+22.1k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+12.2k Golang : List running EC2 instances and descriptions
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+11.6k How to tell if a binary(executable) file or web application is built with Golang?
+32k Golang : Validate email address with regular expression
+12.6k Android Studio : Highlight ImageButton when pressed on example
+15.1k Golang : Get HTTP protocol version example
+8.2k Golang : Number guessing game with user input verification example