GO Program to find power of a number

How to find the power of a number

Here we are explaining how to find the power of a number in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.

 

How to find the power of a number in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing to find the power of a number in the Go language. Here variables num for holding the number for finding the power value, and other variable exp, for holding the exponent, and power holding the result value. The power of a number is found out by using math.Pow(num, exp). Here we must include the header file math for using this built-in function. Given below are the steps which are used in the Go program. 

ALGORITHM

STEP 1: Import the package fmt, math

STEP 2: Start function main()

STEP 3: Declare the variable num, exp

STEP 4: Read the number num using fmt.Scanfln()

STEP 5: Read the exponent exp using fmt.Scanfln()

STEP 6:Find the power of a number using math.Pow(num, exp)

STEP 7: Save the result into the variable power 

STEP 7: Print the result power using fmt.Println()

 

GO Source Code

                                          package main
import (
    "fmt"
    "math"
)

func main() {
    var num, exp float64
    fmt.Print("\nEnter the number to find the Power = ")
    fmt.Scanln(#)
     fmt.Print("Enter the exp Power ", exp, " = ", power)
}
                                      

OUTPUT

Enter the number to find the Power = 3 Enter the exp
3  Power  4  =  81