折腾了半天,总算有了点眉目。
#include<stdio.h>
#include<string.h>
#define MAXN 100
char a1[MAXN + 1], b1[MAXN + 1], a[MAXN + 1],b[MAXN + 1];
int main()
{
int i ,j, c, s, len, lena, lenb;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(a1,0,sizeof(a1));
memset(b1,0,sizeof(b1));
while(scanf("%s%s",a1,b1))
{
if(!strcmp(a1,"0")&&!strcmp(b1,"0")) break;
lena = strlen(a1);
lenb = strlen(b1);
len = lena >= lenb ? lena : lenb;
for(i = 0; i <= lena-1; i++) a[lena-i-1] = a1[i]- '0';
for(i = 0; i <= lenb-1 ; i++) b[lenb-1-i] = b1[i]- '0';
for(i = 0, s = c = 0; i <= len; i++)
{
s = a[i] + b[i] + c;
a[i] = s % 10;
c = s / 10;
}
for(i = MAXN; i >= 0; i--)if(a[j = i])break;
for(; j >= 0; j--) printf("%d",a[j]);
printf("\n");
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(a1,0,sizeof(a1));
memset(b1,0,sizeof(b1));
}
return 0;
}