!********************************************** !* 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". * !* ------------------------------------------ * !* Sample run: * !* * !* GCD and SCM of integer numbers: * !* * !* First number: 9936 * !* Next number : 414 * !* Next number : 3174 * !* Next number : 0 * !* * !* GCD = 138. * !* SCM = 228528. * !* * !* F90 Version By J-P Moreau * !* (www.jpmoreau.fr) * !********************************************** program Test_gcd implicit none real*4 pg, pp, x, xx, GCD print *,' ' print *,'GCD and SCM of integer numbers:' print *,' ' write(*,100,advance='no'); read *, pg pp=pg 10 write(*,110,advance='no'); read *, x xx=x if (x>0.) then pg=GCD(pg,xx) xx=x pp=pp*xx/GCD(pp,xx) end if if(abs(x)<1e-10) goto 20 goto 10 20 print *,' ' write(*,200) pg write(*,210) pp print *,' ' stop 100 format(' First number : ') 110 format(' Next number : ') 200 format(' GCD = ',F12.0) 210 format(' SCM = ',F12.0) end real*4 FUNCTION GCD(a,b) implicit none real*4 a, b, r, temp a = int(abs(a)) b = int(abs(b)) if (a>1e10.or.b>1e10) then GCD=1; return endif if (a.eq.0.or.b.eq.0) then GCD=1; return endif if (a1e-10) goto 1010 GCD = a return end ! end of file gcd.f90