xref: /csrg-svn/usr.bin/pascal/pdx/test/recur.p (revision 48085)
1*48085Sbostic(*
2*48085Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*48085Sbostic * All rights reserved.
4*48085Sbostic *
5*48085Sbostic * %sccs.include.redist.c%
6*48085Sbostic *
7*48085Sbostic *	@(#)recur.p	5.1 (Berkeley) 04/16/91
8*48085Sbostic *)
9*48085Sbostic
10*48085Sbosticprogram recursion(input, output);
11*48085Sbosticvar	i : integer;
12*48085Sbostic
13*48085Sbosticfunction fact(n : integer) : integer;
14*48085Sbosticbegin
15*48085Sbostic	if n <= 1 then begin
16*48085Sbostic		fact := 1;
17*48085Sbostic	end else begin
18*48085Sbostic		fact := n * fact(n-1);
19*48085Sbostic	end;
20*48085Sbosticend;
21*48085Sbostic
22*48085Sbosticbegin
23*48085Sbostic	i := 3;
24*48085Sbostic	writeln(i:1, '! = ', fact(i):1);
25*48085Sbosticend.
26