我的高精度除法程序
高精度除法(a/b,a为高精度,b为长整型)
const maxn=20; jz=10; var s:string; array [1..255] of integer; longinteger; i,j:integer; c:longint; k:integer; temp:longint; begin write('Please input the larger number a:'); readln(s); long=length(s); for i:=1 to longo do o:=ord(s[longo-i+1])-ord('0'); write('Please input the smaller number b:'); readln(c); temp:=o[longo]; k:=temp div c; temp:=temp mod c; i:=longo; while k=0 do begin if i>1 then temp:=temp*jz+o[i-1] else temp:=temp*jz; k:=temp div c; temp:=temp mod c; dec(i); end; if (i=0) then write('0.'); write(k); j:=1; while ((j<maxn) or (i>=1)) do begin if i>1 then temp:=temp*jz+o[i-1] else temp:=temp*jz; if (i=1) then write('.'); write(temp div c); temp:=temp mod c; dec(i); inc(j); if (temp=0) and (i<=1) then break end; writeln; end.
欢迎大家贴出效率更高的程序
[此贴子已经被作者于2004-10-11 23:21:20编辑过] |