C + + high-precision algorithm, for the novice is still a big challenge, as long as you overcome it, you open a new chapter of programming, algorithm.
I sent this code is not very good, take up a lot of memory and run a long time (not more than 1 seconds), but very good understanding, very suitable for beginners
The essence of the high-precision algorithm is to put the array programming string, and then add the string as a vertical type:
1#include <iostream>2#include <cmath>3#include <cstring>4 using namespacestd;5 intMain ()6 {7 Chara[100010],b[100010]; 8cin>>a>>b;//enter a two string. 9 intc[100010],d[100010],h[100010],n1,n2,i,jw=0;//set three positive-shaped arrays to hold two addend, one for storage and the other. N1n2 to store the length of the string A, B. TenN1=strlen (a);//Save the length of string a into N1 OneN2=strlen (b); A for(i=0; i<n1/2; i++) Swap (a[i],a[n1-1-I.]);//swap the order of the addend strings so that you can align them as if you were adding a vertical type. - for(i=0; i<n2/2; i++) Swap (b[i],b[n2-1-I.]);//Ibid . - for(i=0; i<n1;i++) c[i]=a[i]-'0';//Convert the string C into array A, where-' 0 ' is the way of conversion the for(i=0; i<n2;i++) d[i]=b[i]-'0'; - if(N1>N2) swap (N1,N2);//compare two array lengths, and choose a long to do for loop condition. - for(i=0; i<n2;i++) h[i]=c[i]+D[i]; - for(i=0; i<n2;i++) + { - if(h[i]>=Ten) + { Ajw=h[i]/Ten;//Take rounding ath[i]=h[i]-Ten;//to fall into a position -h[i+1]++; - } - if(jw>0) - { -jw=0;//Initialize rounding in } - } to if(h[n2]!=0) cout<//determine if the highest bit has a carry, then the output. + for(i=n2-1; i>=0; i--) cout<<H[i]; -}a+b High Accuracy algorithm
C + + additive high-precision algorithm