加减程序段
1 //加法过程 2 procedure plus(var a1,b1:arr;var x:arr); 3 var i,k:integer; 4 begin 5 k:=0; 6 for i:=1 to l do 7 begin 8 a1[i]:=a1[i]+b1[i]+k; 9 k:=a1[i] div 10; 10 a1[i]:=a1[i] mod 10; 11 end; 12 if k>0 then begin inc(l);a[l]:=k;end; 13 x:=a1; 14 end; 15 16 //加法函数 17 function plus(a,b:arr):arr; 18 var i,c:integer; 19 begin 20 c:=0; 21 for i:=1 to l do 22 begin 23 a[i]:=a[i]+b[i]+c; 24 c:=a[i] div 10; 25 a[i]:=a[i] mod 10; 26 end; 27 if c>0 then begin inc(l);a[l]:=c;end; 28 plus:=a; 29 end; 30 //减法过程 31 procedure minus(var a:numtype;var la:integer;b:numtype); {计算a=a-b,返回差a及其长度la} 32 var 33 i:integer; 34 begin 35 for i:=1 to la do {逐位相减} 36 begin 37 if a[i]<b[i] {借位} 38 then begin dec(a[i+1]);a[i] :=a[i]+10;end; 39 a[i] :=a[i]-b[i]; {计算差的第i位} 40 end; 41 while a[la]=0 do dec(la); {计算差的实际长度} 42 end;