1. Euclid's algorithm
- Posted by dorian stoilescu <dorians at LAGL.SOROSIS.RO> Dec 31, 1997
- 605 views
-- This is a much simpler variant of Euclid's algorithm -- than the one posted a few days ago. A main tip is that -- there's no need to check for v1 being greater than v2 -- at function entry. If it's smaller, at the first -- iteration t will become v1, v1 will become v2 and v2 -- will become v1, so voila, v1 and v2 *exchange* their -- values. I've also coded it without a reference book -- but I'm sure it is OK for v1>0 and v2>0. Mat. function mcd(integer v1,integer v2) integer t t=remainder(v1,v2) while t!=0 do t=remainder(v1,v2) v1=v2 v2=t end while return v1 end function ?mcd(27,36)