加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c#中的数据类型用于查找阶乘

发布时间:2020-12-15 22:26:22 所属栏目:百科 来源:网络整理
导读:c#中最大的数据类型是什么,或者我应该使用哪种数据类型来查找1619的阶乘.我尝试了ulong和uint64,但是他们修改了我的答案. 解决方法 看这个 https://msdn.microsoft.com/en-us/library/system.numerics.biginteger%28v=vs.110%29.aspx BigInteger是不是更快,
c#中最大的数据类型是什么,或者我应该使用哪种数据类型来查找1619的阶乘.我尝试了ulong和uint64,但是他们修改了我的答案.

解决方法

看这个 https://msdn.microsoft.com/en-us/library/system.numerics.biginteger%28v=vs.110%29.aspx

BigInteger是不是更快,但可以计算大数字

这里和MSDN的简单示例

string positiveString = "91389681247993671255432112000000";
string negativeString = "-90315837410896312071002088037140000";
BigInteger posBigInt = 0;
BigInteger negBigInt = 0;

    try 
    {
         posBigInt = BigInteger.Parse(positiveString);
         Console.WriteLine(posBigInt);
    }
    catch (FormatException)
    {
         Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.",positiveString);
    }

我尝试了自己的榜样并且正在努力

string positiveString = "91389681247993671255432112000000";
string negativeString = "-90315837410896312071002088037140000";
BigInteger b = BigInteger.Parse(positiveString);
BigInteger c = BigInteger.Parse(positiveString);
BigInteger d = b * c;

System.Console.WriteLine(d);
System.Console.ReadLine();

// result 835207383860988607360648144841987935757186784078054400000000000

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读