例子:输入 :1234567890987654321
9876543210123456789
输出 :11111111101111111110
#include <stdio.h> #include <string.h> #define M 200 char s1[M], s2[M]; int a[M], b[M]; int main() { int n1, n2, c, t, i; scanf("%s", s1); scanf("%s", s2); n1 = strlen(s1); n2 = strlen(s2); if (n1<n2) t = n2; else t = n1; c = t; for (i = 0; i<n1; t--, i++) a[t] = s1[n1 - 1 - i] - '0'; for (t = c, i = 0; i<n2; t--, i++) b[t] = s2[n2 - 1 - i] - '0'; for (i = c; i >= 0; i--){ a[i] += b[i]; if (a[i] >= 10){ a[i] -= 10; a[i - 1]++; } } if (a[0] != 0) for (i = 0; i <= c; i++) printf("%d", a[i]); else for (i = 1; i <= c; i++) printf("%d", a[i]); printf("\n"); return 0; }