{***********************************************************************
Print ascending members of the Fibonacci sequence that are representable
as 32-bit signed integers, prefixed by their term numbers, and followed
by the ratio of successive terms, to demonstrate the 1.618...^n growth
(the ratio approaches the golden ratio, (1 + sqrt(5))/2 =
1.6180339887498949, and reaches it (to machine precision) at 41 terms:
the fourth item on each line is the difference from the golden ratio).
***********************************************************************}

PROGRAM Fibonacci3p(input,output);
VAR
   lo		: INTEGER;
   hi		: INTEGER;
   n		: INTEGER;
   golden_ratio	: DOUBLE;
   ratio	: DOUBLE;
BEGIN
   golden_ratio := (1.0 + sqrt(5.0))/2.0;
   lo := 1;
   hi := 1;
   n := 1;
   WHILE hi > 0 DO
   BEGIN
      n := n + 1;
      ratio := hi / lo;
      WRITELN(n : 2, ' ', hi, ratio : 25, ' ', (ratio - golden_ratio) : 21 : 18);
      hi := lo + hi;
      lo := hi - lo
   END
END.
