t101_recursion.pas 359 B

1234567891011121314151617
  1. program t101_recursion;
  2. { t101 -- direct self-recursion. The function's result variable shadows its
  3. own name inside the body; a following '(' must resolve to the function
  4. symbol, not the result slot. }
  5. function fact (N : integer) : integer;
  6. begin
  7. if N <= 1 then
  8. fact := 1
  9. else
  10. fact := N * fact (N - 1)
  11. end;
  12. begin
  13. writeln (fact (5))
  14. end.