TutorialEdge

Challenge 19 - Diff of Squares

Welcome, everyone to the discussion thread for the 19th Go challenge posted to the site :tada:

Feel free to show us how you solved the challenge by posting your solutions below!

The solution to this challenge:

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)
}
1 Like
package main

import "fmt"
import "math"

func DiffSquares(n, m int) int {
  return int(math.Pow(float64(n),2) - math.Pow(float64(m),2))
  // could also be
  //return  n * n - m * m
}

func main() {
  fmt.Println("Calculate The Difference of Squares")
}
package main

import "fmt"

func DiffSquares(n, m int) int {
	return n*n - m*m
}

func main() {
	fmt.Println("Calculate The Difference of Squares")
}