主题:pascal 高精度 乘法
[color=000080]请大家看看我这程序有啥问题,帮忙改一下![/color]
[size=3]type numtype=array[1..500]of word;
var var a,b,c:numtype;
la,lb,i:integer;
s1,s2:string;
procedure cheng(var a:numtype; b:numtype);
var k,l,j:integer;
begin
for j:=1 to la do
begin
for k:=1 to lb do inc(c[j],a[j]*b[k]);[color=FF0000]{这里的 [color=00FF00]k 始终=lb [/color]不知道是什么问题,请大家看看}[/color] c[j+1]:=(a[j]*b[k]) div 10;
c[j]:=(a[j]*b[k]) mod 10;
end;
while c[la+1]<>0 do
begin
la:=la+1;
c[la]:=(a[j]*b[k]) div 10;
c[la-1]:=(a[j]*b[k]) mod 10;
end;
a:=c;
end;
begin
readln(s1);
la:=length(s1);
for i:=1 to la do a[la-i+1]:=ord(s1[i])-48;
readln(r);
readln(s2);
lb:=length(s2);
for i:=1 to lb do b[lb-i+1]:=ord(s2[i])-48;
cheng(a,b);
for i:=la downto 1 do write(a[i]);
end.[/size]
[size=3]type numtype=array[1..500]of word;
var var a,b,c:numtype;
la,lb,i:integer;
s1,s2:string;
procedure cheng(var a:numtype; b:numtype);
var k,l,j:integer;
begin
for j:=1 to la do
begin
for k:=1 to lb do inc(c[j],a[j]*b[k]);[color=FF0000]{这里的 [color=00FF00]k 始终=lb [/color]不知道是什么问题,请大家看看}[/color] c[j+1]:=(a[j]*b[k]) div 10;
c[j]:=(a[j]*b[k]) mod 10;
end;
while c[la+1]<>0 do
begin
la:=la+1;
c[la]:=(a[j]*b[k]) div 10;
c[la-1]:=(a[j]*b[k]) mod 10;
end;
a:=c;
end;
begin
readln(s1);
la:=length(s1);
for i:=1 to la do a[la-i+1]:=ord(s1[i])-48;
readln(r);
readln(s2);
lb:=length(s2);
for i:=1 to lb do b[lb-i+1]:=ord(s2[i])-48;
cheng(a,b);
for i:=la downto 1 do write(a[i]);
end.[/size]