HP Pascal/iX Reference Manual (31502-90022)

8- 7
Example
PROGRAM show_function (input,output);
VAR
n,
coef,
answer: integer;
FUNCTION fact (p: integer) : integer;
BEGIN
IF p > 1 THEN
fact := p * fact (p-1)
ELSE fact := 1
END;
FUNCTION binomial_coef (n, r: integer) : integer;
BEGIN
binomial_coef := fact (n) DIV (fact (r) * fact (n-r))
END;
BEGIN { show_function }
read(n);
FOR coef := 0 TO n DO
writeln (binomial_coef (n, coef));
END. { show_function }