用free pascal编程,利用函数或过程,编写求S=1!+2!+……+n!的程序

来源:百度知道 编辑:UC知道 时间:2024/05/20 06:27:02
我的程序是:program ex02;
var n,i,j:integer;ssum:string;a:array[1..100]of string;
procedure inputit(var n:integer);
begin
assign(input,'5[3]2in.txt');
reset(input);
readln(n);
close(input);
end;
function sum(d,s:string):string;
var i,j,k,m,n:integer;
begin
while length(d)>length(s) do s:='0'+s;
while length(s)>length(d) do d:='0'+d;
n:=0;
for i:=length(s) downto 1 do begin
m:=ord(s[i])-48+ord(d[i])-48+n;
if m>9 then begin
m:=m mod 10;n:=1;
end else n:=0;
s[i]:=chr(m+48);
end;
if n>0 then s:='1'+s;
sum:=s;
end;
function yxd(c:char;v:string):string;
var i,j,m,n,k,p:integer;
begin
p:=ord(c)-48;n:=0;
if p=0 then begin yxd:='0';exit; end else begin
for i:=length(v) downto 1 do begin
m:=(ord(v[i])-48)*p+n;
if m>9 then be

在语法方面的错误,1楼的已经说了,主要是传参和赋值
在逻辑上也有一些错误,例如在函数xianchen中
for i:=1 to length(e) do
while i>1 do e[i]:=e[i]+'0';
这是一个死循环
例如在sum中if n>0 then s:='1'+s; 写在for循环外,这样只能在最后才有可能加1,应该写在for循环内。

var a,b:array[1..10000]of integer;
i,j,len,n:longint;
procedure cheng(x:longint);
var i,g:longint;
begin
g:=0;
for i:=1 to 200 do
begin
a[i]:=g+a[i]*x;
g:=a[i] div 10;
a[i]:=a[i] mod 10;
end;
end;
procedure jia;
var i:longint;
begin
for i:=1 to 200 do
begin
b[i]:=b[i]+a[i];
b[i+1]:=b[i+1]+b[i] div 10;
b[i]:=b[i] mod 10;
end;
end;
begin
assign(input,'sum.in');reset(input);
assign(output,'sum.out');rewrite(output);
readln(n);
a[1]:=1;
for i:=1 to n do
begin
cheng(i);
jia;
end;
j:=200;
while a[