Advertisement
tury345

Untitled

Apr 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. Function getGCD(a As Integer, b As Integer) As Integer
  2.  
  3. Dim c As Integer ' Used to store value of b during while loop
  4.  
  5. ' Check for error condition before starting while loop
  6. If a = 0 And b = 0 Then
  7. ' Store error in return var
  8. getGCD = CVErr(xlErrValue)
  9. Else
  10. ' Simplifies until answer is found
  11. Do While b <> 0
  12. c = b ' holds original value of b so we can put it in a after changing b
  13. b = a Mod b ' changes b
  14. a = c ' store original value of b in a
  15. Loop
  16. ' Store result into return var
  17. getGCD = a
  18. End If
  19.  
  20.  
  21. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement