26 lines
433 B
Text
26 lines
433 B
Text
/* Factorials using the pre-processor. */
|
|
test: procedure options (main);
|
|
|
|
|
|
|
|
%factorial: procedure (N) returns (fixed);
|
|
declare N fixed;
|
|
declare (i, k) fixed;
|
|
|
|
k = 1;
|
|
do i = 2 to N;
|
|
k = k*i;
|
|
end;
|
|
return (k);
|
|
|
|
%end factorial;
|
|
|
|
%activate factorial;
|
|
|
|
declare (x, y) fixed decimal;
|
|
x = factorial (4);
|
|
put ('factorial 4 is ', x);
|
|
y = factorial (6);
|
|
put skip list ('factorial 6 is ', y);
|
|
|
|
end test;
|