C This software FCTRL.FOR is part of the Compaq Fortran kit.
C
C This software is provided as an example that demonstrates a particular
C feature/function of the licensed product. The software is not intended to
C provide a complete solution to any application problem but rather is provided
C as a teaching mechanism.
C
C Users may incorporate any part of this sample into their own source after 
C making appropriate changes to make it suitable for the intended application.
C
C
	PROGRAM FACTORIAL_TEST
C
C This is a simple example program showing recursion in Compaq Fortran.
C
C The program computes and displays the factorials of the integers
C 1:12; factorial of 13 is too big for a 32-bit integer.
C

	INTEGER FACTORIAL

	DO N=1,12
	  WRITE (6,*) N,' factorial is ',FACTORIAL(N)
	END DO
	END

	OPTIONS /RECURSIVE
	INTEGER FUNCTION FACTORIAL (N)
C
C The Factorial of an integer N is N * N-1 * N-2 ... * 1.  This is
C often written as N!.
C
C If N is greater than 2, call ourselves recursively, passing N-1
C to perform the calculation.  Note that each recursive
C call to FACTORIAL will get its own copy of N.
C
C If N is 2, 1 or 0, set result to N.
C
	IF (N .GT. 2) THEN
	  FACTORIAL = FACTORIAL(N-1) * N
	ELSE
	  FACTORIAL= N
	END IF

	RETURN
	END
