package main
import (
"fmt"
)
// x = 2, n = 5
// 2 x 2 x 2 x 2 x 2 = 36
// 4 x 4 x 2 = 36
func pow(x,n int) int{
var hasil int=1
for n > 0 {
fmt.Println("## Iterate")
fmt.Println("PANGKAT =>",n)
if n % 2 == 1 {
fmt.Println("hasil =", hasil , " * " , x, "=",hasil*x)
hasil*=x
}
fmt.Println("n =", n , " / " , 2 ,"=",n/2)
fmt.Println("x =", x , " * " , x ,"=",x*x)
n /= 2
x *= x
}
fmt.Println("HASIL AKHIR ITERATE =>",hasil)
return hasil
}
func main() {
fmt.Println(pow(2,5))
}