今天我写了一个代码,我同学写了一个代码,都是关于用数组算大整数加法的问题。我们都用了一个数组字符储存四位的方法来算的。
</pre><pre name="code" class="cpp">#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
int main()
{
char b[1000],a[1000],c[10];
int d[100],e[100],f[100] ,i, k, len1,len2,sum;
gets(a);
gets(b);
strrev(a);
strrev(b);
memset(d,0,sizeof(d));
memset(e,0,sizeof(e));
memset(f,0,sizeof(f));
for(i = 0, k= 0; i < strlen(a); i+=4)
{
c[0] = a[i], c[1] =a[i+1],c[2] = a[i+2],c[3] = a[i+3],c[4] = '\0';
strrev(c);
d[k++] = atoi(c);
}
len1 = k;
for(i = 0, k = 0; i < strlen(b); i+=4)
{
c[0] = a[i], c[1] =a[i+1],c[2] = a[i+2],c[3] = a[i+3],c[4] = '\0';
strrev(c);
e[k++] = atoi(c);
}
len2 = k;
for(i = 0, k = 0; i< len1|| i < len2; i++)
{
sum = log10(d[i] + e[i])+1;
if(sum > 4) d[i+1] ++, f[k++] = d[i] + e[i] -10000 , f[k]++;
else f[k++] =d[i] + e[i];
}
for(i = k-1; i>= 0; i--) printf("%d",f[i]);
printf("\n");
return 0;
}
这是我的代码