网址:

   这个题不难,一定要注意一些特殊的数字,比如31 71 或 55 55 等;

#include
#include
#include
int main(){ char a[20],b[20],temp[20]; while(scanf("%s%s",a,b) != EOF) { printf("%ld ",(atoi)(a) + (atoi)(b)); int la =strlen(a),lb = strlen(b),ltemp; int i,j; //将位数长的付给a if(la < lb) { strcpy(temp,a); strcpy(a,b); strcpy(b,temp); ltemp = la; la = lb; lb = ltemp; } //将位数短的移位,并且在前面的空余位置给上字符'0' for(i = la - 1, j = lb - 1; i >= la - lb; i--, j--) b[i] = b[j]; for(i = 0; i < la - lb; i++) b[i] = '0'; int result,flag = 0;//标记第一位是否为0 for(i = 0; i < la; i++) { result = (int)(a[i] - '0') + (int)(b[i] - '0'); if(result >= 10) result = result - 10; if(flag == 0 && result ==0) continue; else flag = 1; printf("%d",result); } if(flag == 0) printf("0"); printf("\n"); } return 0;}