VB Function过程求最大公约数和最小公倍数
'Function过程求最大公约数和最小公倍数
Private Function gys(ByVal m%, ByVal n%) As Integer
Dim r As Integer
Do '辗转相除法
r = m Mod n
If r = 0 Then Exit Do
m = n
n = r
Loop
gys = n
End Function
Private Sub Command1_Click()
Dim a%, b%, x%, y%
a = 16: b = 12
x = gys(a, b)
y = (a * b) / x
Print "最大公约数为:" & x
Print "最小公倍数为:" & y
End Sub