program phase06c

    procedures
      factorial (n : int) : int;
      fibonacci (n : int) : int ;
      swap (var a : real,var b : real);
      sort (var a : real,var b : real,var c : real);

begin

  procedure main

      variables
        m : int;
        x : real;
        y : real;
        z : real;

  begin
    repeat
      write ("enter a positive integer: ");
      readln (m);
      if (m < 0)
        then break;
      writeln ("factorial: ",factorial(m));
      writeln ("fibonacci: ",fibonacci(m));
      writeln ();
      write ("enter three real numbers: ");
      readln (x,y,z);
      writeln ("the data entered is:");
      writeln (x," ",y," ",z);
      call sort (x,y,z);
      writeln ("the data in increasing order is:");
      writeln (x," ",y," ",z);
      writeln ();
    until (0);
  end

  procedure factorial

  begin
    if ((n = 0) or (n = 1))
      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 swap

      variables
        temp     : real;

  begin
    temp := a;
    a := b;
    b := temp;
  end

  procedure sort

  begin
    if (a > b)
      then call swap(a,b);
    if (b > c)
      then do
           call swap(b,c);
           if (a > b)
             then call swap(a,b);
           end;
  end

end
