Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function getGCD(a As Integer, b As Integer) As Integer
- Dim c As Integer ' Used to store value of b during while loop
- ' Check for error condition before starting while loop
- If a = 0 And b = 0 Then
- ' Store error in return var
- getGCD = CVErr(xlErrValue)
- Else
- ' Simplifies until answer is found
- Do While b <> 0
- c = b ' holds original value of b so we can put it in a after changing b
- b = a Mod b ' changes b
- a = c ' store original value of b in a
- Loop
- ' Store result into return var
- getGCD = a
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement