![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
#include <string>
#include <iostream>
using namespace std;
void add(string a,string b,char sum[],int& count)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int len1=a.length();
int len2=b.length();
int i=len1-1,j=len2-1,temp=0,carry=0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
count=0;
while(i>=0&&j>=0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp=a[i]-'0'+b[j]-'0'+carry;
sum[count++]=temp%10+'0';
carry=temp/10;
--i;
--j;
}
while(i>=0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp=a[i]-'0'+carry;
sum[count++]=temp%10+'0';
carry=temp/10;
--i;
}
while(j>=0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp=b[j]-'0'+carry;
sum[count++]=temp%10+'0';
carry=temp/10;
--j;
}
if(carry>0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sum[count++]='1';
}
}
void print(char arr[],int len)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int i;
for(i=len-1;i>=0;--i)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
cout<<arr[i];
}
cout<<endl;
}
int main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
string a,b;
char sum[2000];
int count,cs;
cin>>count;
for(cs=1;cs<=count;cs++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int len;
cin>>a>>b;
cout<<"Case "<<cs<<":"<<endl;
cout<<a<<" + "<<b<<" = ";
add(a,b,sum,len);
print(sum,len);
if(cs!=count)
cout<<endl;
}
return 0;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)