RECURSIVE FUNCTION gcd(a,b) RESULT (r)
  IMPLICIT NONE
  INTEGER, INTENT (inout) :: a,b
  INTEGER :: r

  INTEGER :: c

  IF (a < b) THEN
     c = a
     a = b
     b = c
  END IF
  
  IF (b == 0) r = a
  
  IF (b > 0) THEN
     c = MOD(a,b)
     r = gcd(b, c)
  END IF
END FUNCTION gcd



PROGRAM mkd
  IMPLICIT NONE
  INTERFACE
     RECURSIVE FUNCTION gcd(a,b) RESULT (r)
       IMPLICIT NONE
       INTEGER, INTENT (inout) :: a,b
       INTEGER :: r
     END FUNCTION gcd
  END INTERFACE
  INTEGER :: a, b
  a = 135
  b = 680
  
  PRINT *, gcd(a,b)
END PROGRAM mkd
