【问题描述】数学上定义:
n!=1×2×3×...×(n-1)×n (N>0)
0!=1 若用integer型数据表示阶乘,最多可到7!,用Longint类型也只能到12!
要求输入正整数n,求 n! 的精确表示
【参考程序】
const max=1000;
var n,i,j,jinwei,weishu:integer;
result:array[1..max] of integer;
begin
writeln('input n:');readln(n);
fillchar(result,sizeof(result),0);
result[1]:=1;
jinwei:=0;
weishu:= 1 ;
for i:=2 to n do begin
jinwei:=0;
for j:=1 to weishu do begin
result[j]:= result[j]*i+jinwei ;
jinwei:=result[j] div 10;
result[j]:=result[j] mod 10;
end;
while jinwei<>0 do begin
weishu:=weishu+1;
result[weishu]:=jinwei mod 10;
jinwei:= jinwei div 10 ;
end;
if weishu>max then begin writeln('error!');halt;end;
end;
write(n,'!=');
for i:= weishu downto 1 do write(result[i]);readln;
end.