#include <stdio.h>
// 倒序字符串
void str_rts(char *s)
{
char*p=s;
while(*p) p++;
p--;
for(;s < p;s++,p--)
{
*p ^= *s;
*s ^= *p;
*p ^= *s;
}
}
char b[] =
"1283461973258176325874124\
35878032743712098317867293728651279";
char a[] =
"9080202033923787772398789\
50493849938744869530984603429835934";
char c[200];
int main()
{
char *pa = a;
char *pb = b;
//定义各位数的整型值存储
int ga,gb,gc,flag = 0;//flag 进位标志
int i = 0; //c中的存储位置
printf("a=%60s\nb=%60s\n",a,b);
//找到ab的末尾字符地址
while(*pa) pa++;
pa --;
while(*pb) pb++;
pb --;
//按位计算 从末尾开始
for(;a <= pa || b <= pb ; pa--,pb--,i++)
{
if(pa >= a)//判断指针越界否
ga = *pa - '0';
else
ga = 0;//a 短于 b 补0
if(pb >= b)
gb = *pb - '0';
else
gb = 0;//b 短于 a 补0
gc = ga + gb + flag;
if(gc > 9)//判断是否进位
{
flag = 1;
gc %= 10;
}
else
{
flag = 0;
}
c[i] = gc + '0';
}
//判断溢出否
if(flag)
c[i++] = '1';
//给c添加结束符'\0'
c[i] = '\0';
//倒叙c
str_rts(c);
printf("c=%s\n",c);
printf("i=%d\n",i);
return 0;
}