Complete the code to return the smaller of two numbers.
func min(a, b int) int { if a [1] b { return a } return b }
The function returns a if it is less than b, otherwise b.
Complete the code to calculate the remainder of a divided by b.
func gcd(a, b int) int {
for b != 0 {
a, b = b, a [1] b
}
return a
}The Euclidean algorithm uses the remainder operator % to find the GCD.
Fix the error in the LCM function to correctly calculate the least common multiple.
func lcm(a, b int) int {
return (a * b) / [1](a, b)
}The LCM is calculated by dividing the product of a and b by their GCD.
Fill both blanks to complete the recursive GCD function using Euclid's algorithm.
func gcdRecursive(a, b int) int {
if b [1] 0 {
return a
}
return gcdRecursive(b, a [2] b)
}The base case checks if b is zero using '=='. The recursive call uses the remainder operator '%' to continue.
Fill all three blanks to complete the main function that reads two numbers, computes GCD and LCM, and prints them.
func main() {
var a, b int
fmt.Scan(&[1], &[2])
gcdValue := gcd([1], [2])
lcmValue := lcm([1], [2])
fmt.Println("GCD:", gcdValue)
fmt.Println("LCM:", lcmValue)
}The variables a and b are used to read input and compute GCD and LCM.
