CS 3304: Comparative Languages
Implementing Subprograms
[ Course Documents ] : [ Implementing Subprograms ]
Previous Slide Lecture Contents Next Slide Index
Previous Contents Next Keyword Index

Example Factorial Program (1)

    program p;
        var v : int;

        function fac(n: int): int;
        begin
            if n <= 1 then
                fac := 1
            else
                fac := n * fac(n--1);
        end;

    begin
        v := fac(3);
        print(v);
    end.