This Go program uses the math pow function to find the power of a number. To use this function, you have to import the math module.
package main import ( "fmt" "math" ) func main() { var pnum, expo float64 fmt.Print("\nEnter the Number to find the Power = ") fmt.Scanln(&pnum) fmt.Print("Enter the Exponent Value = ") fmt.Scanln(&expo) power := math.Pow(pnum, expo) fmt.Println(pnum, " Power ", expo, " = ", power) }
Golang program to Find Power of a Number
In this golang program, the for loop iterate numbers from 1 to exponent value. Within that, we are multiplying the given number and assigning it to power.
package main import "fmt" func main() { var i, pnum, expo, power int power = 1 fmt.Print("\nEnter the Number to find the Power = ") fmt.Scanln(&pnum) fmt.Print("Enter the Exponent Value = ") fmt.Scanln(&expo) for i = 1; i <= expo; i++ { power = power * pnum } fmt.Println(pnum, " Power ", expo, " = ", power) }