I'm trying to write Fibonacci code for the first 100
numbers. It works until I get to number 94.

93 12200160415121876738 ok
94 1293530146158671551 mine
94 19740274219868223167 should be this

I'm stumped as to why it doesn't work after 93. Can
someone point me in the right direction? The code
is below.

    static void Main(string[] args)
    {
        //Figure out the 1st 100 numbers in Fibinacci Seq.
        List<ulong> fibs = new List<ulong>();
        ulong x1 = 0;
        ulong x2 = 1;
        fibs.Add(0);
        fibs.Add(1);
        int count = 2;
        ulong x3 = 0; //new number. x1 + x2 = x3

        while (count < 100)
        {
            x3 = x1 + x2; //new number
            fibs.Add(x3);

            Console.WriteLine("Count {0,3} {1,-15}", count, x3);
            x1 = x2;
            x2 = x3;
            count += 1;
        }
        //print to console
        for (int i = 0; i < count; i++)
        {
            Console.WriteLine("Count {0,3} {1,-15}", i, fibs[i]);
        }

    }

ULong largest number is 18,446,744,073,709,551,615
Your next number is bigger 19,740,274,219,868,223,167

For the same reason, my code snippet also goes to 93.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.