In this challenge, you are going to implement the DiffSquares function so that it returns the difference between the first number squared minus the second number squared.
5^2 - 4^2 = 9
If you require a hint as to how this is done, please click below: You can calculate powers of numbers in Go using the Hint
math.Pow function. You can read more about this here: Math PowView Solution
package main
import (
"fmt"
"math"
)
func DiffSquares(n, m int) int {
x := math.Pow(float64(n), 2)
y := math.Pow(float64(m), 2)
return int(x) - int(y)
}
func main() {
fmt.Println("Calculate The Difference of Squares")
result := DiffSquares(5, 4)
fmt.Println(result)
}
If you like this challenge then you may also appreciate some of the following articles on the site: