The high-precision subtraction (A-B) (A>b and A, a, a, a, are positive integers). Read two positive integers from the keyboard to find their difference. Analysis: Similar to addition, can be used in vertical subtraction. When doing subtraction, it is important to note that the minuend must be larger than the meiosis and need to deal with borrow. Reference program for high-precision subtraction:
1 Programexam2;2 Const3max= $;4 var5A,b,c:Array[1.. Max of 0..9;6 n,n1,n2:string;7 Lena,lenb,lenc,i,x:integer;8 begin9 READLN (N1);TenReadln (N2);{treatment of meiosis and meiosis} One if(Length (N1) <length (n2))or(Length (N1) =length (n2)) and(N1<N2) Then A begin -n:=n1;n1:=n2;n2:=N; -Write ('-'){N1<N2, the result is negative} the End; -Lena:=length (N1); lenb:=Length (n2); - fori:=1 toLena Doa[lena-i+1]:=ord (N1[i])-ord ('0'); - fori:=1 toLenB Dob[lenb-i+1]:=ord (N2[i])-ord ('0'); +i:=1; -x:=0; + while(I<=lena)or(I<=LENB) Do A begin atx: = A[i]-B[i] +Ten+ x;{do not consider the size of the problem, first to borrow ten} -C[i]: = XMoD Ten;{Save the value of the bit I} -x: = XDiv Ten-1;{minus 1 of the high-level loan.} -I: = i +1 - End; -lenc:=i; in while(c[lenc]=0) and(lenc>1) DoDec (LENC);{0 of the highest bit does not output} - forI:=lencDownto 1 Dowrite (c[i]); to Writeln + End.
High Precision Subtraction