5
[Golang] Integer Exponentiation
source link: https://siongui.github.io/2017/05/20/go-integer-exponentiation/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[Golang] Integer Exponentiation
May 20, 2017Integer exponentiation in Go programming language.
package main import ( "fmt" ) // return a^n func Power(a, n uint) uint { var i, result uint result = 1 for i = 0; i < n; i++ { result *= a } return result } func main() { fmt.Println(Power(2, 0)) fmt.Println(Power(2, 1)) fmt.Println(Power(2, 2)) fmt.Println(Power(2, 3)) }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK