#include<stdio.h>
#include<string.h>
struct bignum
{
int digit[1001];
int size;
void init()
{
for (int i = 0; i <= 1000; i++)
digit[i] = 0;
size = 0;
}
void tiqu(char str[])
{
init();
int L = strlen(str);
for (int i = L - 1; i >= 0; i--)
digit[size++] = str[i] - '0';
}
void output()
{
for (int i = size - 1; i >= 0; i--)
printf("%d", digit[i]);
printf("\n");
}
}a,b,c;
bignum plus(bignum a, bignum b)
{
bignum c;
c.init();
int carry;
for (int i = 0; i < a.size || i < b.size; i++)
{
int temp = a.digit[i] + b.digit[i] + carry;
carry = temp / 10;
temp = temp % 10;
c.digit[c.size++] = temp;
}
if (carry)
c.digit[c.size++] = carry;
return c;
}
int main()
{
char str1[1000], str2[1000];
while (scanf("%s%s", str1, str2) != EOF)
{
a.tiqu(str1);
b.tiqu(str2);
c = plus(a, b);
c.output();
}
return 0;
}
大数加法器
最新推荐文章于 2021-10-02 19:28:06 发布