FUNCTION parag(k)
  IMPLICIT NONE
  INTEGER, INTENT (in) :: k
  INTEGER :: parag

  INTEGER :: i

  parag = 1 
  DO i=1,k
     parag = parag * i
  ENDDO

END FUNCTION parag

FUNCTION myexp(x)
  IMPLICIT NONE
  DOUBLE PRECISION, INTENT (in) :: x
  DOUBLE PRECISION :: myexp

  INTEGER :: i

  INTERFACE
     FUNCTION parag(k)
       IMPLICIT NONE
       INTEGER, INTENT (in) :: k
       INTEGER :: parag
     END FUNCTION parag
  END INTERFACE

  myexp = 0.0d0
  DO i = 0,12
     myexp = myexp + x**i / parag(i)
  ENDDO

END FUNCTION myexp


PROGRAM expseries
  IMPLICIT NONE

  DOUBLE PRECISION :: x

  INTERFACE
     FUNCTION myexp(x)
       IMPLICIT NONE
       DOUBLE PRECISION, INTENT (in) :: x
       DOUBLE PRECISION :: myexp
     END FUNCTION myexp
  END INTERFACE

  x = 0.5d0
  PRINT *, myexp(x), EXP(x), myexp(x) - EXP(x)

  x = 1.2d0
  PRINT *, myexp(x), EXP(x), myexp(x) - EXP(x)

  x = 4.1d0
  PRINT *, myexp(x), EXP(x), myexp(x) - EXP(x)

END PROGRAM expseries
