Calculating the n root

Report a typo

You already know that the math package has the math.Sqrt() and math.Cbrt() functions to calculate the square and cube roots of float64 types; but what if we needed to calculate the n root of a number?

Create a Go program that takes as an input two numbers as variables: the num you will calculate the root of, and the n root you want to calculate. Then, after calculating the n root, print the output with two decimals.

The first hint to solve this task is that you can use the math.Pow() function to calculate the n root of any number... in case you don't know yet how to use the math.Pow() function to do this, you may use the second hint below.

Tip: We can easily calculate the n root of num raising it to the power of 1/n with the help of the math.Pow() function

Sample Input 1:

32768
5

Sample Output 1:

8.00
Write a program in Go
package main

import (
"fmt"
"math"
)

func main() {
var num float64
fmt.Scanln(&num)

var n float64
fmt.Scanln(&n)

// calculate the 'n' root of 'num' using the math.Pow() function below
root := math.Pow(?, ?)

fmt.Printf("%.2f", root)
}
___

Create a free account to access the full topic