更多“高精度减法procedure substract(a,b:hp;var c:hp); var i,len:integer; ”相关问题
  • 第1题:

    高精度乘以低精度

    procedure multiply(a:hp;b:longint;var c:hp);

    var i,len:integer;


    正确答案:

     

    begin
    fillchar(c,sizeof(c),0);
    len:=a[0];
    for i:=1 to len do begin
    inc(c[i],a[i]*b);
    inc(c[i+1],(a[i]*b) div 10);
    c[i]:=c[i] mod 10;
    end;
    inc(len);
    while (c[len]>=10) do begin {处理最高位的进位}
    c[len+1]:=c[len] div 10;
    c[len]:=c[len] mod 10;
    inc(len);
    end;
    while (len>1) and (c[len]=0) do dec(len); {若不需进位则调整len}
    c[0]:=len;
    end;{multiply}

  • 第2题:

    高精度除以低精度

    procedure devide(a:hp;b:longint; var c:hp; var d:longint);

    {c:=a div b; d:= a mod b}

    var i,len:integer;


    正确答案:

     

    begin
    fillchar(c,sizeof(c),0);
    len:=a[0]; d:=0;
    for i:=len downto 1 do begin
    d:=d*10+a[i];
    c[i]:=d div b;
    d:=d mod b;
    end;
    while (len>1) and (c[len]=0) then dec(len);
    c[0]:=len;
    end;

  • 第3题:

    下列各函数首部中,正确的是()。

    A.void play(var :Integer, var b:Integer)

    B.void play(int a, b)

    C.void play(int a, int b)

    D.Sub play(a as integer, b as integer)


    void play(int a,int b)

  • 第4题:

    高精度乘以高精度

    procedure high_multiply(a,b:hp; var c:hp}

    var i,j,len:integer;


    正确答案:

     

    begin
    fillchar(c,sizeof(c),0);
    for i:=1 to a[0] do
    for j:=1 to b[0] do begin
    inc(c[i+j-1],a[i]*b[j]);
    inc(c[i+j],c[i+j-1] div 10);
    c[i+j-1]:=c[i+j-1] mod 10;
    end;
    len:=a[0]+b[0]+1;
    while (len>1) and (c[len]=0) do dec(len);
    c[0]:=len;
    end;

  • 第5题:

    高精度除以高精度

    procedure high_devide(a,b:hp; var c,d:hp);

    var

    i,len:integer;


    正确答案:

     

    begin
    fillchar(c,sizeof(c),0);
    fillchar(d,sizeof(d),0);
    len:=a[0];d[0]:=1;
    for i:=len downto 1 do begin
    multiply(d,10,d);
    d[1]:=a[i];
    while(compare(d,b)>=0) do {即d>=b}
    begin
    Subtract(d,b,d);
    inc(c[i]);
    end;
    end;
    while(len>1)and(c.s[len]=0) do dec(len);
    c.len:=len;
    end;