In the lab session on 4th March 1998, you are required to submit a listing of your solution and demonstrate it to the TA.
function gcd(a, b)
{
var r, x, y
x = a
y = b
while (y != 0)
{
// Invariant:
// gcd(a,b)=gcd(x,y)
r = x % y
x = y
y = r
}
return x
}
|