使用高精度减法模拟除法过程,并且逐位相减。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 type arr=array[0..1000]of longint;
2 procedure divide(a,b:arr;var c,d:arr); //a div b=c;a mod b=d;
3 var i,j:longint;
4 begin
5 fillchar(c,sizeof(c),0);
6 fillchar(d,sizeof(d),0);
7 for i:=a[0] downto 1 do
8 begin
9 multiply(d,10); //高精度乘以单精度,向左移一位
10 d[1]=a[i];
11 inc(d[0]);
12 while compare(d,b) do //高精度比较
13 begin
14 minus(d,b); //高精度减法
15 inc(c[i]);
16 end;
17 end;
18 c[0]:=a[0];
19 while (c[c[0]]=0)and(c[0]>1) do dec(c[0]);
20 end;
21