Uh, let's start with the idea that if you add large numbers, you can't use int, float, double, long.... You should use char arrays.
Comparing the length of two arrays, add them up from the tail, and subtract 10 from more than 10. In one case, it should be noted that when the array length is equal, the processing of the first element greater than 10
In fact, I think there is another problem that needs to be considered, the problem of leading 0, when the front of the array is invalid 0, for example, 00006 + 05 = 11, rather than 00011. Although the results are the same, the format is...
#include<stdio.h> #include<string.h> int main(void) { char a[1005], b[1005], count = 1; int len_a, len_b, temp, j, T; scanf("%d", &T); for (int i = 1; i <= T; i++) { scanf("%s %s", a, b); len_a = strlen(a); len_b = strlen(b); j = 0; printf("Case %d:\n", count++); printf("%s + %s = ", a, b); for (int i = 0; i < len_a; i++) { a[i] = a[i] - '0'; } for (int i = 0; i < len_b; i++) { b[i] = b[i] - '0'; } if (len_a > len_b) { for (int i = len_a - len_b, j = 0; i < len_a; i++) { a[i] += b[j++]; } for (int i = len_a-1; i >= 0; i--) { if (a[i] > 9) { a[i] = a[i] - 10; a[i-1]++; } } for (int i = 0; i < len_a; i++) { printf("%d", a[i]); } } else { for (int i = len_b - len_a, j = 0; i < len_b; i++) { b[i] += a[j++]; } for (int i = len_b-1; i > 0; i--) { if (b[i] > 9) { b[i] = b[i] - 10; b[i-1]++; } } if (b[0] > 9) { printf("1"); b[0] = b[0] - 10; } for (int i = 0; i < len_b; i++) { printf("%d", b[i]); } } if(i != T) { printf("\n\n"); }else{ printf("\n"); } } return 0; }