Search code examples
c#.netvariablescluster-computingfactorial

Variable "cluster" to count factorial in c#


Trying to count factorial of a big number, for example 1000!

static void Main(string[] args)
        {
            UInt64 fact = 1;

            for (UInt64 i = 1000; i > 0; i--)
            {
                fact = fact * i;
            }
            Console.WriteLine(fact); //returns 0, due to overflow UInt64, max fact is 56!

            Console.ReadKey();
        }

So i ask, if there is some way to join more variables to cluster, so i can make really large variable to store "big" number.


Solution

  • You can use a BigInteger. This type can store integers of arbitrary size, until you run out of memory.