我自己写的阶乘函数如下:
public int getJieCheng(int M)
{
int ResultVal = 1;
if((M==1)||(M==0))
ResultVal = 1;
else
{
while(M > 1)
{
ResultVal = ResultVal * M;
M--;
}
}
return ResultVal;
}当M小于等于12时,是正确的;当M大于12时就不正确了,不知道为什么。
public int getJieCheng(int M)
{
int ResultVal = 1;
if((M==1)||(M==0))
ResultVal = 1;
else
{
while(M > 1)
{
ResultVal = ResultVal * M;
M--;
}
}
return ResultVal;
}当M小于等于12时,是正确的;当M大于12时就不正确了,不知道为什么。
for (int i = 2; i <= n; i++)
{
r = r * (double)i;
}
return r;
换成其他更大数据类型比如double,或者BigInteger