program recursive

  procedures
    factorial (n : int        ) : int;
    fibonacci (n : int        ) : int;
    strange   (n : int,c : int);

begin

  procedure main

    variables
      i     : int;
      start : int;
      count : int;

  begin
    for i := 1 upto 20
      writeln (i," factorial is: ",factorial (i));
    writeln ();
    for i := 0 upto 20
      writeln (i," fibonacci is: ",fibonacci (i));
    writeln ();
    write ("enter a positive integer: ");
    readln (start);
    count := 1;
    call strange (start,count);
  end

  procedure factorial

  begin
    if (n = 0)
      then return 1;
      else return n * factorial (n-1);
  end

  procedure fibonacci

  begin
    if ((n = 0) or (n = 1))
      then return 1;
      else return fibonacci (n-1) + fibonacci (n-2);
  end

  procedure strange

  begin
    if (c = 20)
      then return;
    if (n = 1)
      then do
           writeln (n);
           return;
           end;
      else do
           write (n," ");
           if (n % 2 = 0)
             then call strange (n/2,c+1);
             else call strange (3*n + 1,c+1);
           end;
  end

end
