image University of Washington Computer Science & Engineering
  CSE 401Sp '04:  PL/0 - Sample Code
  CSE Home   About Us    Search    Contact Info 

The following PL/0 program is fib.0. What does it do?
module main;
    var result:int;

    procedure fib(arg:int);
	var temp:int;
    begin
	if arg <= 0 then result := 0; end;
	if arg  = 1 then result := 1; end;
	if arg  > 1 then
		fib(arg - 1);
		temp := result;
		fib(arg - 2);
		result := result + temp;
	end;
    end fib;

    var n:int;

begin

    n := input;
    while n <> 0 do
        fib(n);
        output := result;
        n := input;
    end;

end main.


CSE logo Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to cse401-webmaster at cs.washington.edu]