vb程序题目:输入两个正整数M和N,求他们的最小公倍数

谢谢咯~~ 明天考试的题目啊啊!!

Private Function GetMinNum(m As Integer, n As Integer) As Integer
Dim tm As Integer, tn As Integer, t As Integer
tm = m
tn = n
If tm <= 0 Or tn <= 0 Then
GetMinNum = -1
Exit Function
End If
if tm < tn Then
t = tn
tn = tm
tm = t
End If
t = tm Mod tn
While t
tm = tn
tn = t
t = tm Mod tn
Wend
GetMinNum = m * n / tm
End Function

Private Sub Command1_Click()
Dim m As Integer
Dim n As Integer
Dim min As Integer
m = Int(InputBox("请输入正整数m"))
n = Int(InputBox("请输入正整数n"))
min = GetMinNum(m, n)
If min > 0 Then
MsgBox "2数的最小公倍数为:" & min
Else
MsgBox "输入的整数不符要求!"
End If
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-20
Private Sub Form_Click()
Dim m As Integer, n As Integer
m = InputBox("请输入一个整数:")
n = InputBox("请再输入一个整数:")
If m < n Then
t = m
m = n
n = t
End If
For i = n To m * n Step n
If i Mod m = 0 And i Mod n = 0 Then
Print i
Exit For
End If
Next i
End Sub
第2个回答  推荐于2017-11-25
private sub form_cilck()
M=inputbox("请输入M的值:")
N=inputbox("请输入N的值:")
if M>N then
max=M
else
max=N
for i = max to M*N
if i mod M = 0 and i mod N = 0 then
print "M和N的最小公倍数是:";i
exit for
end if
next i
end sub
手打的
没有测试过
但是理论上没有错``
加分及分```本回答被网友采纳
相似回答