Yes, I know Fibonacci(=sun of a good man) again.
Most famous for his series, but who among you all, know that he was the man who introduced to the Western world, the Arabic numeral system(including zero) in 1202 A.D.? The Italian merchands of those days adored it. It was far more easy to work with than the roman numeral system of course. And it is still in use today.
I did the series a little different with a calculation that gives you any Fibonacci number from zero up to the 93th one. I guess the Convert method does the rounding. Also included here in the code, is a little test loop.

Edited by ddanbe: correction

using System;

namespace ConsoleApplication2
    class Program
        static void Main(string[] args)
            for (Byte n = 0; n < 20; n++)
                Console.WriteLine("F({0}) = {1}", n, Fib(n));

        /// <summary>
        /// Calculates the Nth(starting from zero) Fibonacci number
        /// no overflow error checking
        /// </summary>
        /// <param name="n">n can range from 0 to 93</param>
        /// <returns>F(n)</returns>
        public static UInt64 Fib(Byte n)
            double sqrt5 = Math.Sqrt(5);
            double phi = (sqrt5 + 1) / 2;
            return Convert.ToUInt64((1 / sqrt5) * Math.Pow(phi, n));
3 Years
Discussion Span
Last Post by Triryche

That explains it. I'm somewhat of a math geek, suprise I never heard of that. I was wondering why you went through all of that instead of simple addition.


I don't understand how Console.WriteLine**("F({0}) = {1}"**, n, Fib(n));
produces F(0),F(1)F(2)...


{0} and {1} are placeholders for the second and third arguments to WriteLine respectively. So {0} is replaced with the value of n (the second argument) and {1} is replaced with the value of Fib(n) (the third argument). So Console.WriteLine("F({0}) = {1}"**, n, Fib(n)) will print F(3) = 6 when n is 3.

For more information see Composite Formatting (MSDN).

PS: If that wasn't your question, please clarify.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.