高精度计算阶乘pascal程序。
function mult(x,y:string):string;
var
a,b,c:array[1..255] of shortint;
ia,ib,ic:integer;
i,j,k:integer;
m,p,q:integer;
temp:string;
t:string[1];
begin
ia:=length(x);
ib:=length(y);
for i:=1 to ia do a[i]:=ord(x[ia+1-i])-ord('0');
for i:=1 to ib do b[i]:=ord(y[ib+1-i])-ord('0');
for i:=1 to 255 do c[i]:=0;
for i:=1 to ia do begin
p:=0; {进位}
for j:=1 to ib do begin
m:=a[i]*b[j]+p+c[i+j-1];
q:=m mod 10;
c[i+j-1]:=q;
p:=m div 10;
end;
c[i+ib]:=p;
end;
k:=0;
for i:=255 downto 1 do if c[i]<>0 then
begin k:=i; break; end;
temp:='';
for i:=k downto 1 do begin str(c[i]:1,t); temp:=temp+t; end;
mult:=temp;
end;
var
n,i:integer;
s,st:string;
begin
n:=10;
st:='1';
for i:=2 to n do begin
str(i:0,s);
st:=mult(st,s);
writeln(i:3,' ',st);
end;
end.
void main()
{
int a;
long jc(int);
for(a=1;a<=10;a++)
{
printf("%d ! = %ld",a,jc(a));
}
}
long jc(int x)
{
if(x==0)
{
return 1;
}
else
{
return x*jc(--x);
}
}