Addition operation of decimal large number

Source: Internet
Author: User

The first behavior of the input file is an integer n, which indicates that the input file is followed by n sets of data, no group of data contains a maximum of 100 rows, each line has a very long decimal integer, the length of the integer is no more than 100 characters, and contains only numbers, the last behavior of each group of data 0, indicating the end of the set

For each set of data on the input file, output their and.

This problem is different from the two large numbers added, is the addition of multiple large numbers, when summed, has its unique: vertical addition

#include <iostream>#include<stdio.h>#include<string.h>Const intm= $;using namespacestd;intMain () {CharBuffer[m]; intArray[m][m],answer[m]; intn,maxn,len,num_integers,carry,sum,digit,l;  while(cin>>N) {         for(intk=1; k<=n;k++) {MAXN=-1; memset (Array,0,sizeof(array)); memset (Answer,0,sizeof(answer));  for(num_integers=0;num_integers< -; num_integers++) {gets (buffer); if(strcmp (Buffer,"0")==0) Break; Len=strlen (buffer); if(len>maxn) MAXN=Len;  for(intj=len-1, m=0; j>=0; j--) Array[num_integers][m++]=buffer[j]-'0'; } Carry=0;  for(intI=0; i<maxn+2; i++) {sum=carry;  for(intj=0; j<num_integers;j++) {sum+=Array[j][i]; Digit=sum%Ten; Carry=sum/Ten; Answer[i]=Digit; }        }         for(l=maxn+2; l>=0; l--)            if(answer[l]!=0)                 Break;  while(l>=0) {cout<<answer[l--]; } cout<<Endl; }    }    return 0;}

Addition operation of decimal large number

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.