Program with factorial procedure that uses recursion to calculate the factorial: program recurse; var i, j: integer; procedure fact(var n, f: integer); var m, g: integer; begin writeln(' fact in: ', n); {debugging output} if n <= 1 then begin f := 1; end else begin m := n - 1; fact(m, g); f := n * g; end; writeln(' fact out: ', f); {debugging output} end; begin write('n? '); readln(i); fact(i, j); writeln(i:5, ' factorial is ',j:6); readln; end. Note that the statements flagged with {debugging output} would normally not be included but are here to give some clues as to how it all works. Sample output: >n? <4 > fact in: 4 > fact in: 3 > fact in: 2 > fact in: 1 > fact out: 1 > fact out: 2 > fact out: 6 >fact out: 24 > 4 factorial is 24