using System; class Fibonacci3 { /** Print ascending members of the Fibonacci sequence that are representable as 64-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). */ static double golden_ratio = (1.0 + Math.Sqrt(5.0))/2.0; public static void Main() { long lo = 1L; long hi = 1L; long n = 1L; double ratio; Console.Write("{0,2:D}", n); Console.Write("\t"); Console.WriteLine("{0,25:N0}", lo); while (hi > 0L) { n++; Console.Write("{0,2:D}", n); Console.Write("\t"); Console.Write("{0,25:N0}", hi); Console.Write("\t"); ratio = (double)hi/(double)lo; Console.Write("{0,26:F15}", ratio); Console.Write("\t"); Console.WriteLine("{0,26:F15}", ratio - golden_ratio); hi = lo + hi; lo = hi - lo; } } }