#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int lena,lenb;
int i,j,k,maxx;
char a[1500],b[1500],c[1500],jin;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
while(scanf("%s%s",a,b)!=EOF)
{
jin='0';
lena=strlen(a);
lenb=strlen(b);
maxx=lena>lenb?lena:lenb;
//printf("maxx=%d\n",maxx);
//printf("lena=%d,lenb=%d\n",lena,lenb);
j=1400;
lena--;
lenb--;
for(i=maxx-1;i>=0;i--)
{
if(lena>=0&&lenb>=0)
{c[j]=a[lena]-'0'+b[lenb]-'0'+jin;
jin='0';}
else if(lena>=0&&lenb<0)
{c[j]=a[lena]-'0'+jin;
jin='0';}
else if(lenb>=0&&lena<0)
{c[j]=b[lenb]-'0'+jin;
jin='0';}
//printf("c[j]==%c\n",c[j]);
if(c[j]>'9')
{
c[j]=c[j]-'9'+'0'-1;
jin='1';
}
//printf("c[j]jin==%c\n",c[j]);
lena--;
lenb--;
j--;
}
j++;
if(jin=='1')
{
j--;
c[j]='1';
}
//printf("%d\n",j);
for(;j<=1400;j++)
{
printf("%c",c[j]);
}
printf("\n");
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
}
return 0;
}
C语言基础篇:大数的加法
最新推荐文章于 2023-03-11 17:55:22 发布