[求助]求两个自然数的最大公约数和最小公倍数
要求输入两个整数m和n,程序计算并在窗体上显示它们的最大公约数和最小公倍数。Dim m As Integer, n As Integer
m = Val(InputBox("请输入第一个数"))
n = Val(inutbox("请输入第二个数"))
后面怎么写才能求得最大公约数和最小公倍数?
高手指点!
Option Explicit
Private Sub Command1_Click()
Dim m As Integer
Dim n As Integer
Dim t As Integer, r As Integer, s As Integer
m = InputBox("请输入第一个数")
n = InputBox("请输入第二个数")
s = m * n
If m < n Then
t = m
m = n
n = t
End If
r = m Mod n
Do While r <> 0
m = n
n = r
r = m Mod n
Loop
Print "最大公约数:"; n
Print "最小公倍数:"; s / n
End Sub