root/branch/twedit/gcd.f

Revision 1262, 0.8 kB (checked in by mswat, 2 years ago)
Line 
1*     euclid.f (FORTRAN 77)
2*     Find greatest common divisor using the Euclidean algorithm
3
4      PROGRAM EUCLID
5        PRINT *, 'A?'
6        READ *, NA
7        IF (NA.LE.0) THEN
8          PRINT *, 'A must be a positive integer.'
9          STOP
10        END IF
11        PRINT *, 'B?'
12        READ *, NB
13        IF (NB.LE.0) THEN
14          PRINT *, 'B must be a positive integer.'
15          STOP
16        END IF
17        PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.'
18        STOP
19      END
20
21      FUNCTION NGCD(NA, NB)
22        IA = NA
23        IB = NB
24    1   IF (IB.NE.0) THEN
25          ITEMP = IA
26          IA = IB
27          IB = MOD(ITEMP, IB)
28          GOTO 1
29        END IF
30        NGCD = IA
31        RETURN
32      END
Note: See TracBrowser for help on using the browser.