VB中的 两个数最大公约数的语句是什么

来源:百度知道 编辑:UC知道 时间:2024/05/15 04:50:24
程序设计~~~

完整代码如下:
Dim a, b, i As Integer
Private Sub Command1_Click()
a = Val(InputBox(输入第一个数))
b = Val(InputBox(输入第二个数))
If a < b Then
For i = 1 To a
If a Mod i = 0 And b Mod i = 0 Then
Print "a和b的最大公约数有" & i
End If
Next i
Else
For i = 1 To b
If a Mod i = 0 And b Mod i = 0 Then
Print a; "和"; b; "的最大公约数有" & i
End If
Next i
End If
End Sub

Function gcd(ByVal a As Long, ByVal b As Long) As Long
    Dim d As Long
    Do
        d = a Mod b
        a = b
        b = d
    Loop While d
    gcd = a<