vb求两个数字的最大公约数和最小公倍数。
展开全部
Public Function zuidagy() As Integer
Dim m, n, r, t As Integer
m = InputBox("输入第一个自然数")
n = InputBox("输入第二个自然数")
If m < n Then t = m : m = n : n = t
r = m Mod n
Do While (r <> 0)
m = n
n = r
r = m Mod n
Loop
Return n
End Function
Public Function zuixiaogb() As Integer
Dim m, n, r, t, nm As Integer
m = InputBox("输入第一个自然数")
n = InputBox("输入第二个自然数")
nm = n * m
If m < n Then t = m : m = n : n = t
r = m Mod n
Do While (r <> 0)
m = n
n = r
r = m Mod n
Loop
Return nm / n
End Function
Public Function zuidazuixiao()
Dim m, n, r, t, nm As Integer
m = InputBox("输入第一个自然数")
n = InputBox("输入第二个自然数")
nm = n * m
If m < n Then t = m : m = n : n = t
r = m Mod n
Do While (r <> 0)
m = n
n = r
r = m Mod n
Loop
MsgBox("最大公约数为" & n)
MsgBox("最小公倍数为" & nm / n)
Return 0
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询