什么数据类型可用于保存 100,000,000 的阶乘值? [英] What data type can be used to hold the value of the factorial of 100,000,000?
本文介绍了什么数据类型可用于保存 100,000,000 的阶乘值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要容纳非常大的数字(例如 1000 位或更多位)的数据类型?我需要找到一个大数的阶乘,比如 100000000.我的阶乘程序适用于较小的数字.
Data type to hold a very large number say 1000 or more digits? I need to find the factorial of a large number say 100000000. My factorial program works nice for a smaller number.
long factorial(int x)
{
long fact=1;
if(x<0)
{
System.out.println("Incorrect input, enter a positive number");
fact=0;
}
if(x==0)
fact=1;
if(x>0)
{
fact=x;
fact=fact*factorial(x-1);
}
return fact;
}
推荐答案
您需要一个 BigInteger
.它可以容纳任意大的数字.
You need a BigInteger
. It can hold an arbitrarily large number.
但就您而言,100000000!
是一个巨大的数字,没有任何帮助.
But in your case 100000000!
is such a huge number, that nothing can help.
这篇关于什么数据类型可用于保存 100,000,000 的阶乘值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文