PASCAL高精度小数计算

来源:百度知道 编辑:UC知道 时间:2024/05/12 00:04:56
帮忙
请告诉我代码

和整数一样的。。记录下小数点位置

加法
var s,s1,s2 : string;
a,b,c : array [1..260] of integer;
i,l,k1,k2 : integer;
begin
write('input s1:');readln(s1);
write('input s2:');readln(s2);
while (length(s1)-pos('.',s1))<(length(s2)-pos('.',s2)) do s1:=s1+'0';
while (length(s1)-pos('.',s1))>(length(s2)-pos('.',s2)) do s2:=s2+'0';
l:=length(s1);
k1:=260;
for i:=l downto 1 do
if s1[i]<>'.' do begin
a[k1]:=ord(s1[i])-48;
k1:=k1-1;
end;
k1:=k1+1;

l:=length(s2);
k2:=260;
for i:=l downto 1 do begin
b[k2]:=ord(s2[i])-48;
k2:=k2-1;
end;
k2:=k2+1;

if k1>k2 then k:=k2 else k:=k1;
y:=0;
for i:=260 downto k do
begin
x:=a[i]+b[i]+y;
c[i]:=x mod 10;
y:=x div 10;
end;
if y<>0 then begin k:=k-1;c[k]:=y;
end;
for i