summaryrefslogtreecommitdiffstats
path: root/regress/roff/de/factorial.in
blob: 48c2e9a87101a68980fed5abba2a66e81d8c6a9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
.\" $OpenBSD: factorial.in,v 1.2 2017/07/04 14:53:27 schwarze Exp $
.Dd $Mdocdate$
.Dt FACTORIAL 1
.Os
.Sh NAME
.Nm factorial
.Nd factorial sequence
.Sh DESCRIPTION
.\" recursively calculate a single factorial
.de rfac
.  ie \\$1>1 \{\
.    No \\$1 *
.    nr i \\$1-1
.    rfac \\ni
.    nr acc \\n[acc]*\\$1
.  \}
.  el .nr acc 1
..
.\" recursively print a sequence of factorials
.de fac
.  No \\$1! =
.  rfac \\$1
.  if \\$1>1 1 =
.  No \\n[acc]
.  if \\$1 \{\
.    br
.    nr i \\$1-1
.    fac \\ni
.  \}
..
.\" main program
.fac 9