#include <stdio.h>
#include <string.h>
#define N 500
void BigNumAdd(char *n1, char *n2){
char result[N], *p1, *p2, *p3 = result, temp;
int n = 0, rn1, rn2, i;
//p1、p2分别指向n1、n2的个位数
p1 = n1+(strlen(n1)-1)*sizeof(char);
p2 = n2+(strlen(n2)-1)*sizeof(char);
while (p1 >= n1 || p2 >= n2){
//获取真实数值
rn1 = p1 >= n1 ? *p1-'0' : 0;
rn2 = p2 >= n2 ? *p2-'0' : 0;
//保留个位
*p3 = (rn1+rn2+n) % 10 + '0';
n = (rn1+rn2+n) >= 10 ? 1 : 0;
p1--;
p2--;
p3++;
}
if(n){
*p3 = '1';
p3++;
}
*p3 = '\0';
for(i = 0; i < strlen(result) / 2; i++){
temp = result[i];
result[i] = result[strlen(result)-i-1];
result[strlen(result)-i-1] = temp;
}
printf("%s\n", result);
}
int main(int argc, char *argv[]) {
BigNumAdd("12311", "100211");
return 0;
}