gpt4 book ai didi

c# - 变量 "cluster"用于计算 C# 中的阶乘

转载 作者:太空宇宙 更新时间:2023-11-03 18:37:17 24 4
gpt4 key购买 nike

尝试计算一个大数的阶乘,例如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();
}

所以我想问,是否有某种方法可以将更多变量加入集群,这样我就可以创建非常大的变量来存储“大”数。

最佳答案

您可以使用 BigInteger .这种类型可以存储任意大小的整数,直到内存不足。

关于c# - 变量 "cluster"用于计算 C# 中的阶乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13489986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com