You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lavos/cap3/ex31.go

35 lines
461 B

5 months ago
package cap3
func Ex31(a, b, c int) int {
lcm, maxNum := 0, 0
maxNum = max(a, b, c)
for i := 2; i <= maxNum; i++ {
hasDivisible := true
for hasDivisible {
hasDivisible = false
if a%i == 0 {
a = a / i
hasDivisible = true
}
if b%i == 0 {
b = b / i
hasDivisible = true
}
if c%i == 0 {
c = c / i
hasDivisible = true
}
if hasDivisible {
lcm = lcm * i
}
}
maxNum = max(a, b, c)
}
return lcm
}