aboutsummaryrefslogtreecommitdiff
path: root/examples/factorial.imp
blob: 4cb47edd363b3dc52adbd3ab2d131fa9437bf373 (plain)
1
2
3
4
5
6
7
8
9
10
/* computes n!, result is stored in r. */
procedure factorial(n;r) begin
  if n <= 0 then
    r := 1;
  else
    m := n - 1;
    factorial(m;r);
    r := r * n;
  end;
end;