qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
RECURSE.PAS
  Example Contents Index                                    Back
 
PROGRAM recurse;
 
{ RECURSE.PAS : Demonstrates recursion. }
 
VAR
    num    : Byte;
    result : Real;
 
FUNCTION factor( value: Byte ) : Real;
BEGIN
    IF ( value > 1 ) THEN
        factor := value * factor( value - 1 )
    ELSE
        factor := 1.0;
END; { factor }
 
BEGIN
 
    Write( 'Enter a number smaller than 34: ' );
    Readln( num );
    result := factor( num );
    Write( 'Factorial of ', num, ' is ' );
    Writeln( result );
 
END.