HP Pascal/iX Reference Manual (31502-90022)
Table Of Contents
- Top of Document
- Preface
- Chapter 1 Introduction
- Chapter 2 Language Elements
- Chapter 3 Data Types
- Chapter 4 Expressions
- Chapter 5 The Declaration Section
- Chapter 6 Statements
- Chapter 7 Program Structure
- Chapter 8 Procedures and Functions
- Chapter 9 Standard Routines
- Chapter 10 Input and Output
- Chapter 11 System Programming Extensions
- Chapter 12 Compiler Options
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 }