这个大数加法错哪里了?
哪些部分有问题啊?
#include<stdio.h>
#include<string.h>
void swapStr(char *a)
{
short i;
int len;
len = strlen(a);
for(i=0;i<len/2;i++)
{
a[i]^=a[len-i-1];
a[len-i-1]^=a[i];
a[i]^=a[len-i-1];
}
}
int main()
{
short T;
short temp;
int lena,lenb,i,carry;
char a[1002],b[1002],c[1002];
scanf("%d",&T);
for(int j=1;j<=T;j++)
{
i = 0;
carry = 0;
memset(a,0,1002);
memset(b,0,1002);
memset(c,0,1002);
scanf("%s%s",a,b);
lena = strlen(a);
lenb = strlen(b);
while(lena>0&&lenb>0)
{
temp = a[lena-1]-'0'+ b[lenb-1]-'0'+carry;
c[i] = temp%10+'0';
carry = temp/10;
lena--;
lenb--;
i++;
}
while(lena>0)
{
temp = a[lena-1]+carry-'0';
c[i] = temp%10+'0';
carry = temp/10;
lena--;
i++;
}
while(lenb>0)
{
temp = b[lenb-1]+carry-'0';
c[i] = temp%10+'0';
carry = temp/10;
lenb--;
i++;
}
if(carry)
c[i] = carry+'0';
swapStr(c);
printf("case %d:\n",j);
printf("%s + %s = %s\n\n",a,b,c);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define MAXLEN 1000
char a1[MAXLEN];
char a2[MAXLEN];
static int v1[MAXLEN];
static int v2[MAXLEN];
static int v3[MAXLEN];
int i,j,n,L,z;
void main(void) {
scanf("%d",&n);
for (j=0;j<n;j++) {
scanf("%s%s",a1,a2);
L=strlen(a1);
for (i=0;i<L;i++) v1[i]=a1[L-1-i]-'0';
L=strlen(a2);
for (i=0;i<L;i++) v2[i]=a2[L-1-i]-'0';
for (i=0;i<MAXLEN;i++) v3[i]=v1[i]+v2[i];
for (i=0;i<MAXLEN;i++) {
if (v3[i]>=10) {
v3[i+1]+=v3[i]/10;
v3[i]=v3[i]%10;
}
}
printf("Case %d:\n", j+1);
printf("%s + %s = ", a1, a2);
z=0;
for (i=MAXLEN-1;i>=0;i--) {
if (z==0) {
if (v3[i]!=0) {
printf("%d",v3[i]);
z=1;
}
} else {
printf("%d",v3[i]);
}
}
if (z==0) printf("0");
printf("\n");
}
}
//Sample Input
//3
//0 0
//1 2
//112233445566778899 998877665544332211
//
//Sample Output
//Case 1:
//0 + 0 = 0
//Case 2:
//1 + 2 = 3
//Case 3:
//112233445566778899 + 998877665544332211 = 1111111111111111110