高精度除以整型数据(integer)

[复制链接]
发表于 2023-12-30 09:43:44 | 显示全部楼层 |阅读模式
高精度除以整型数据(integer);
程序如下:
programHighPrecision3_Multiply1;
const
  fn_inp='hp5.inp';
  fn_out='hp5.out';
  maxlen=100;  { max length of the number }
type
  hp=record
       len:integer; { length of the number }
       s:array[1..maxlen] of integer
       { s[1]   is the lowest position
         s[len] is the highest position}
     end;
var
  x,y:hp;
  z,w:integer;
procedure PrintHP(const p:hp);
  var i:integer;
  begin
    for i:=p.len downto 1 do write(p.s);
  end;
procedure init;
  var
    st:string;
    i:integer;
  begin
    assign(input,fn_inp);
    reset(input);
    readln(st);
    x.len:=length(st);
    for i:=1 to x.len do { change string to HP }
      x.s:=ord(st[x.len+1-i])-ord('0');
    readln(z);
    close(input);
  end;
procedure Divide(a:hp;b:integer;var c:hp;var d:integer);
  { c:=a div b ; d:=a mod b }
  var i,len:integer;
  begin
    fillchar(c,sizeof(c),0);
    len:=a.len;
    d:=0;
    for i:=len downto 1 do { from high to low }
    begin
      d:=d*10+a.s;
      c.s:=d div b;
      d:=d mod b;
    end;
    while(len>1) and (c.s[len]=0) do dec(len);
    c.len:=len;
  end;
procedure main;
  begin
    Divide(x,z,y,w);
  end;
procedure out;
  begin
    assign(output,fn_out);
    rewrite(output);
    PrintHP(y);
    writeln;
    writeln(w);
    close(output);
  end;
  begin
    init;
    main;
    out;
  end.

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表