求两个数的最公倍数

来源:百度知道 编辑:UC知道 时间:2024/06/08 13:27:28
Private Sub Form_Click()
Dim a As Long, b As Long, c As Long, d As Long, e As Long, f As Long
a = Val(Text1.Text)
b = Val(Text2.Text)
Do While a Mod b <> 0
c = a Mod b
a = b
b = c
Loop
d = Val(Text1.Text) / b
e = Val(Text2.Text) / b
f = b * d * e
Print f
End Sub
----------------------------------以上是我写的,大家看有什么缺点没?或者还有什么更好的算法没?--------------------------------
最小公倍数

算法没有问题,求最小公倍数,先求最大公约数
小改一下
Dim a, b, c, d, e As Long
a = Val(Trim(Text1.Text))
b = Val(Trim(Text2.Text))
c = a Mod b
Do While c <> 0
a = b
b = c
c = a Mod b
Loop
d = Val(Trim(Text1.Text)) / b
e = d * Val(Trim(Text2.Text))
print e
愚见仅供参考