1 #include<stdio.h> 2 #include<string.h> 3 4 #define N 100 5 6 int main() 7 { 8 9 char a[N], b[N]; 10 int a_real[N], b_real[N], c[N + 1]; 11 12 int i, j, k = 0; 13 int a_len, b_len; 14 int max, min; 15 int carry_bit = 0, total_bit = 0; 16 17 memset(c, 0, sizeof(c)); 18 memset(a_real, 0, sizeof(a_real)); 19 memset(b_real, 0, sizeof(b_real)); 20 21 scanf("%s", &a); 22 scanf("%s", &b); 23 24 a_len = strlen(a); 25 b_len = strlen(b); 26 27 i = a_len - 1; 28 j = b_len - 1; 29 30 while(i != -1) 31 { 32 a_real[k++] = a[i--] - '0'; 33 } 34 35 36 k = 0; 37 while(j != -1) 38 { 39 b_real[k++] = b[j--] - '0'; 40 } 41 42 max = a_len > b_len ? a_len : b_len; 43 min = a_len > b_len ? b_len : a_len; 44 45 for(i = 0; i < max; i++) 46 { 47 c[i] = a_real[i] + b_real[i] + carry_bit; 48 49 if(c[i] > 9) 50 { 51 c[i] -= 10; 52 carry_bit = 1; 53 } 54 else 55 { 56 carry_bit = 0; 57 } 58 59 } 60 61 if(carry_bit) 62 { 63 c[max] = 1; 64 total_bit = max + 1; 65 } 66 else 67 { 68 total_bit = max; 69 } 70 71 for(i = total_bit - 1; i >= 0; i--) 72 { 73 printf("c[%d]:%d\n", i, c[i]); 74 } 75 76 }