VBA 最大公約数(ユークリッドの互除法)を出す
Sub 最大公約数()
Dim a As Long
Dim b As Long
Dim c As Long
Dim n As Long
Dim m As Long
a = InputBox("a = ")
b = InputBox("b = ")
If a > b Then
n = a
m = b
Else
n = b
m = a
End If
Do
c = n Mod m
If c = 0 Then
Call MsgBox(m)
Else
n = m
m = c
End If
Loop Until c = 0
End Sub