如何输入最大整数 [英] how to input Biggest integer

查看:93
本文介绍了如何输入最大整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何输入这种类型的数字并保存在任何变量中并打印出来..

数字就像这样...

2318678973167632186632156464312357431213574631247864132153346979

解决方案

使用 BigInteger [ ^ ](在.NET中可用) 4.0及更高版本。

首先,添加对 System.Numerics.dll 的引用。

然后,添加这个在代码文件的顶部:

 使用 System.Numerics; 



现在,使用 BigInteger.Parse [ ^ ]解析你的号码的方法:

 BigInteger b = BigInteger.Parse(  2318678973167632186632156464312357431213574631247864132153346979); 
// 现在,您可以使用它进行一些其他操作,例如乘法,除法...
Console.WriteLine(b.ToString()); // 在控制台上打印大号



希望这有帮助。


在.NET 4以后,您可以像使用任何其他整数类型一样使用BigInteger实例。 BigInteger重载标准数字运算符,使您能够执行基本的数学运算,如加法,减法,除法,乘法,减法,否定和一元否定。



参考: http://msdn.microsoft.com/en-us/library/system.numerics。 biginteger.aspx [ ^ ]

how to input this type of numbers and save in any variable and print it..
Number Like this...
2318678973167632186632156464312357431213574631247864132153346979

解决方案

Use a BigInteger[^] (available in .NET 4.0 and higher).
First, add a reference to System.Numerics.dll.
Then, add this at the top of your code file:

using System.Numerics;


Now, use the BigInteger.Parse[^] method to parse your number:

BigInteger b = BigInteger.Parse("2318678973167632186632156464312357431213574631247864132153346979");
// now, you can do some other operations with it such as multiplying, dividing ...
Console.WriteLine(b.ToString()); // prints the large number on the console


Hope this helps.


In .NET 4 onward, you can use a BigInteger instance as you would use any other integral type. BigInteger overloads the standard numeric operators to enable you to perform basic mathematical operations such as addition, subtraction, division, multiplication, subtraction, negation, and unary negation.

Ref: http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx[^]


这篇关于如何输入最大整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆