c++
string sum(string s1,string s2)
{
if(s1.length()<s2.length())
{
string temp=s1;
s1=s2;
s2=temp;
}
int i,j;
for(i=s1.length()-1,j=s2.length()-1;i>=0;i--,j--)
{
s1[i]=char(s1[i]+(j>=0?s2[j]-'0':0));
if(s1[i]-'0'>=10)
{
s1[i]=char((s1[i]-'0')%10+'0');
if(i) s1[i-1]++;
else s1='1'+s1;
}
}
return s1;
}
C语言
char s1[1000];
char s2[1000];
void Add1()
{
int num1[2000],num2[20000];
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
int i,j;
int len1=strlen(s1);
int len2=strlen(s2);
for(i=len1-1,j=0;i>=0;i--)
num1[j++]=s1[i]-'0';
for(i=len2-1,j=0;i>=0;i--)
num2[j++]=s2[i]-'0';
for(i=0;i<2000;i++)
{
num1[i]+=num2[i];
if(num1[i]>9)
{
num1[i]-=10;
num1[i+1]++;
}
}
for( i=1999;i>=0;i--)
if(num1[i]!=0)
break;
if(i==-1)
printf("0",num1[i]);
for(;i>=0;i--)
printf("%d",num1[i]);
printf("
");
}