以文本方式查看主题

-  趣题之家  (http://www.qthome.org/bbs/index.asp)
--  算法艺术  (http://www.qthome.org/bbs/list.asp?boardid=38)
----  我的高精度除法程序  (http://www.qthome.org/bbs/dispbbs.asp?boardid=38&id=141)

--  作者:趣题之主
--  发布时间:10/3/2004 8:28:24 PM

--  我的高精度除法程序

高精度除法(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编辑过]

--  作者:wwmfeng
--  发布时间:11/3/2004 12:21:09 PM

--  
4 位4位算 可以提高速度
--  作者:ppatsname
--  发布时间:11/3/2004 6:28:53 PM

--  
这是单精度吧


网上贸易 创造奇迹! 阿里巴巴 Alibaba

Powered By Dvbbs Version 7.1.0
Copyright ©2003 - 2006 QTHome.Org
页面执行时间 00.68359 秒, 5 次数据查询
本论坛采用阿里巴巴支付宝网上银行支付系统,安全、可靠、便捷