完整代码如下:
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
End Function