vb测试题5

来源:百度知道 编辑:UC知道 时间:2024/06/07 02:02:14
输入两个正整数m和n,求其最大公约数和最小公倍数。

参考代码:

Private Function Gcf(m As Long, n As Long) As Long
If n = 0 Then
Gcf = m
Else
Gcf = Gcf(n, m Mod n)
End If
End Function

Private Function Lcm(m As Long, n As Long) As Long
Lcm = m * n / Gcf(m, n)
End Function

Private Sub Command1_Click()
Print Gcf(120, 84)
Print Lcm(120, 84)
End Sub