- 高精度乘法
- 2009-08-02 14:52:44 @
const
maxn = 1000;
var
a,b,c : array[1..maxn] of byte;
i,j,w1,w2 : integer;
ch : char;
begin
Write(' a = ');
w1 := 0;
while not eoln do begin
read(ch);
inc(w1);
c[w1] := ord(ch)-48;
end;
readln;
for i := 1 to w1 do a[w1+1-i] := c[i];
Write(' b = ');
w2 := 0;
while not eoln do begin
read(ch);
inc(w2);
c[w2] := ord(ch)-48;
end;
readln;
for i := 1 to w2 do b[w2+1-i] := c[i];
fillchar(c,sizeof(c),0);
for j := 1 to w2 do begin
for i := 1 to w1 do
c := c+a[i]*b[j];
for i := 1 to j+w1 do
if c[i] > 9 then begin
c := c+c[i] div 10;
c[i] := c[i] mod 10;
end;
end;
j := w1+w2;
while c[j] = 0 do dec(j);
write('a*b = ');
for i := j downto 1 do Write(c[i]);
WriteLn;
ReadLn;
end.
1 条评论
-
yinguohang LV 4 @ 2009-08-18 19:57:42
你没有压位,百分之百超
- 1