divisor of 2 numbers
- Posted by Carlos Valdis <cvaldes at NCS.COM> Dec 29, 1997
- 666 views
-- This is euclides algorithm implemented nonrecursively -- to find the maximum common divisor of 2 numbers --somebody asked for something similar a few days ago --using variables v1 v2 v3 -- I coded it without a reference book. I think it is OK. include get.e function mcd(integer v1,integer v2) integer v3,t if v1<v2 then t=v1 v1=v2 v2=t end if while 1 do t=remainder(v1,v2) if t=0 then v3=v2 exit else v1=v2 v2=t end if end while return v3 end function integer v1,v2,v3,cc for i=1 to 10 by 1 do v1=rand(10000) v2=rand(10000) v3=mcd(v1,v2) printf(1,"%d\n",v1) printf(1,"%d\n",v2) printf(1,"%d\n",v3) cc=wait_key() end for