ps3真北斗神拳dlc:求一段阶乘,随意输入一个数,将输入的一个数乘到1,得出结果.要将程序写出,运行得即可.

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 01:39:31
求一段阶乘,随意输入一个数,将输入的一个数乘到1,得出结果.要将程序写出,运行得即可.

main()
{
int i, n;
long t = 1;

printf("\nInput n: ");
scanf("%d", &n);

for(i = 1; i <= n; i++)
t *= i;

printf("Result: %ld", t);
getch();
}

上面的程序只要t的数值一当超过int的最大值就出问题!

import java.math.BigInteger;

public class Test20060630_02 {

public static void main(String[] args) {
BigInteger result = new BigInteger("1");
int input = 50;
for (int i = 1; i <= input; i ++) {
result = result.multiply(BigInteger.valueOf(i));
}
System.out.println(result);
}
}

function GetCount(Count:Integer):LongWord;
var
I:Integer;
begin
I:=1;
while I<Count do
begin
Result:=Result*I;
Inc(i);
end;
end;