pascal高精度计算1!+2!+…+n!求改用高精度计算出S=1!+2!+3!+...+n!(n=10 then begin h[q]:=h[q]-10;h[q+1]:=h[q+1]+1;end;end;end;i:=100;while h[i]=0 do i:=i-1;for j:=i downto 1 do write(h[i]);end.--------------------------------------分割
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 21:59:15
pascal高精度计算1!+2!+…+n!求改用高精度计算出S=1!+2!+3!+...+n!(n=10 then begin h[q]:=h[q]-10;h[q+1]:=h[q+1]+1;end;end;end;i:=100;while h[i]=0 do i:=i-1;for j:=i downto 1 do write(h[i]);end.--------------------------------------分割
pascal高精度计算1!+2!+…+n!求改
用高精度计算出S=1!+2!+3!+...+n!(n=10 then begin h[q]:=h[q]-10;h[q+1]:=h[q+1]+1;end;
end;
end;
i:=100;
while h[i]=0 do i:=i-1;
for j:=i downto 1 do write(h[i]);
end.
--------------------------------------分割线-----------------------------------------
阶乘能算出来,相加的时候有问题,应该怎么改?
program jiecheng;
type arr=array[-5..105] of integer;
var a,h:arr;
n,i,j,k,p,q:integer;
procedure jc(var a:arr;k:integer);
var i,x,t:integer;
begin
t:=0;
for i:=1 to 100 do
begin
x:=a[i]*k+t;
t:=x div 10;
a[i]:=x mod 10;
end;
end;
begin
read(n);
fillchar(h,sizeof(h),0);
fillchar(a,sizeof(a),0);a[1]:=1;
for p:=1 to n do
begin
jc(a,p);
i:=100;
while a[i]=0 do i:=i-1;
for q:=1 to i do
begin
h[q]:=h[q]+a[q];
while h[q]>=10 do begin h[q]:=h[q]-10;h[q+1]:=h[q+1]+1;end;
{ h[q+1]:=h[q+1]+(h[q] div 10);
h[q]:=h[q] mod 10;}
end;
end;
i:=100;
while h[i]=0 do i:=i-1;
for j:=i downto 1 do write(h[i]);
end.
pascal高精度计算1!+2!+…+n!求改用高精度计算出S=1!+2!+3!+...+n!(n=10 then begin h[q]:=h[q]-10;h[q+1]:=h[q+1]+1;end;end;end;i:=100;while h[i]=0 do i:=i-1;for j:=i downto 1 do write(h[i]);end.--------------------------------------分割
if h[q]>=10 then begin h[q]:=h[q]-10;h[q+1]:=h[q+1]+1;end;
这句话改成while循环,因为不止进位一次,怎么改不用我说了吧?
祝你noip成功,年年岁岁花相似,岁岁年年人不同,又是一批人呀.(感慨一下)