Alexis12345
New Member
- Joined
- Oct 12, 2020
- Messages
- 5
- Office Version
- 2019
- Platform
- Windows
Hi,
I have the following codes for VBA excel to compute GCD of 2 numbers, how can I continue from here to compute GCD of 3 numbers?
Sub GCD()
Dim small As Integer, large As Integer
Dim temp As Integer, remainder As Integer, k As Integer
' input the two positive integers
small = InputBox("Enter the first number: ")
large = InputBox("Enter the second number: ")
' make sure that L is the larger one and S is the smaller one:
If small > large Then
temp = large
large = small
small = temp
End If
k = 0 ' counter to keep track of the number of iterations
Do
remainder = large Mod small
large = small
small = remainder
k = k + 1 ' increase counter by 1
Loop While remainder <> 0
MsgBox "After " & k & " iterations, we found the GCD: " & large
End Sub
I have the following codes for VBA excel to compute GCD of 2 numbers, how can I continue from here to compute GCD of 3 numbers?
Sub GCD()
Dim small As Integer, large As Integer
Dim temp As Integer, remainder As Integer, k As Integer
' input the two positive integers
small = InputBox("Enter the first number: ")
large = InputBox("Enter the second number: ")
' make sure that L is the larger one and S is the smaller one:
If small > large Then
temp = large
large = small
small = temp
End If
k = 0 ' counter to keep track of the number of iterations
Do
remainder = large Mod small
large = small
small = remainder
k = k + 1 ' increase counter by 1
Loop While remainder <> 0
MsgBox "After " & k & " iterations, we found the GCD: " & large
End Sub