include int main(){ int arr1[20], arr2[20], sum[20] = {0}; int count = 0, a, b, i, temp; scanf("%d %d", &a, &b); while (a != 0 || b != 0) { arr1[count] = a % 10; arr2[count] = b % 10; a /= 10; b /= 10; count++; } for (i = 0; i < count; i++) { temp = arr1[i] + arr2[i]; sum[i] += temp % 10; sum[i + 1] = temp / 10; } if (sum[count]) printf("%d", sum[count]); else printf("%d", sum[count - 1]); return 0;}把两个数拆开,每个位相加,处理进位。因为这是加法,所以结果的长度和两数中最长的那个相同,或者比它大1,if判断一下哪个是最高位就行了。sum存储的是两数和的每一位,它的所有元素的初始值都被置为0.