'********************************************** '* Geatest common divisor and Smallest common * '* multiple of several integer numbers * '* ------------------------------------------ * '* Ref.: "Mathematiques en Turbo-Pascal By * '* M. Ducamp and A. Reverchon (2), * '* Eyrolles, Paris, 1988" [BIBLI 05]. * '* ------------------------------------------ * '* Sample run: * '* * '* GCD and SCM of integer numbers: * '* * '* First number: 9936 * '* Next number : 414 * '* Next number : 3174 * '* Next number : 0 * '* * '* GCD = 138 * '* SCM = 228528 * '* * '* BASIC Version By J-P Moreau * '* (www.jpmoreau.fr) * '********************************************** cls print print " GCD and SCM of integer numbers:" print input " First number: ", pg : pp=pg 10 input " Next number : ", x if x>0 then a=pg:b=x:gosub 1000: pg=xx 'pg=GCD(pg,x) a=pp:b=x:gosub 1000 pp=pp*x/xx 'xx=GCD(pp,x) end if if x<>0 then goto 10 print print " GCD = "; pg print " SCM = "; pp print end 'xx=GCD(a,b) 1000 a = int(abs(a)) b = int(abs(b)) if a>1e10 or b>1e10 then xx=1 : return if a=0 or b=0 then xx=1 : return if a1e-10 then goto 1010 xx = a return ' end of file gcd.bas