High accuracy algorithm (high accuracy algorithm)

Source: Internet
Author: User

High-precision addition to the third time study ... I understand the content.

1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 #defineMaxLen 1106 intMain () {7     CharA1[maxlen],b1[maxlen];//the original Addend string entered8     intA[maxlen],b[maxlen],c[maxlen],lena,lenb,lenc,x;//storage of two addend, results, length and rounding of addend results9Memset (A,0,sizeof(a));Tenmemset (b,0,sizeof(b)); OneMemset (c,0,sizeof(c));//Initialize Ascanf"%s%s", A1,B1); -Lena =strlen (A1); -LenB = strlen (B1);//calculates the length of a two string the      for(intI=0; I <= Lena-1; i++) -A[lena-i]=a1[i]-'0';//addend into a array -      for(inti =0; I <= LenB-1; i++) -B[lenb-i]=b1[i]-'0';//Addend into the b array +Lenc =1; -x =0; +      while(Lenc <= Lena | | lenc<=LenB) { AC[LENC] = A[lenc] + B[lenc] +x;//two numbers added atx = C[lenc]/Ten;//Calculate Rounding -C[LENC]%=Ten;//the number of standard reservations -Lenc++; -     }  -C[LENC] =x; -     if(C[lenc] = =0) inlenc--;//handling the highest rounding -      for(inti = Lenc; i>=1; i--) tocout << C[i];//Output Results +cout<<Endl; -     return 0;  the}

High accuracy algorithm (high accuracy algorithm)

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.