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
665 B

7 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
}
7 months ago
if b%i == 0 {
b = b / i
hasDivisible = true
}
7 months ago
if c%i == 0 {
c = c / i
hasDivisible = true
}
7 months ago
if hasDivisible {
lcm = lcm * i
}
}
7 months ago
maxNum = max(a, b, c)
}
7 months ago
return lcm
7 months ago
}