我怎么能容纳100!在任何变量?

时间:2015-09-05 15:16:30

标签: c#

*我在projecteuler中被困在#20中。 我似乎熟悉寻找阶乘的价值,但我无法获得100阶乘的价值。 *

1 个答案:

答案 0 :(得分:1)

如Jon Skeet所述,您应该使用BigInteger

//Add reference of System.Numerics.dll

using System.Numerics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            BigInteger factorial = 1;
            var factorialOfNumber = 100;
            for (var i = 1; i <= factorialOfNumber; i++)
            {
                factorial *= i;
            }
            Console.WriteLine("Required factorial of {0} is {1}", factorialOfNumber, factorial);
        }
    }
}