High Precision Subtraction

Source: Internet
Author: User

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&LT;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&LT;=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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.