Published in: ASP
|
|
|
URL: http://reusablecode.blogspot.com/2008/05/euclids-algorithm.html
Expand |
Embed | Plain Text
<% ' ASP Mathematics Library - Euclid's Algorithm ' ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Determine the greatest common divisor of two numbers using Euclid's algorithm. function gcd(byVal a, byVal b) a = abs(a) b = abs(b) if a = 0 then gcd = b elseif b = 0 then gcd = a elseif a > b then gcd = gcd(b, a mod b) else gcd = gcd(a, b mod a) end if end function ' Determine the least common multiple of two numbers using Euclid's algorithm. function lcm(byVal a, byVal b) a = abs(a) b = abs(b) if a > b then lcm = (b / gcd(a, b)) * a else lcm = (a / gcd(a, b)) * b end if end function %>
You need to login to post a comment.