Well, considering that you have understood the logic and math behind my code completely, I am moving forward.
Ok, then I'm removing tit bits referencing to ca[e-1] and posting the modified code again
#include <stdio.h>
#include <stdlib.h>
int digits(int a){
int k=1;
int x=a;
while (a%10==0){
k--;
a/=10;
}
while(x>9){
x=x/10;
k++;
}
return k;
}
int main() {
int n,j=1;
scanf("%d",&n);
while(n--) {
int a=0,b=0,c=0,d=0,e=0,x=0,m=0,r=0;
scanf("%d %d",&a,&b);
c=digits(a);
d=digits(b);
if(c>d)
e=c;
else
e=d;
while (a%10==0&&b%10==0){
a/=10;
b/=10;
}
int *aa=calloc(e,sizeof(int));
int *ba=calloc(e,sizeof(int));
int *ca=calloc(e,sizeof(int));
while(c--){
aa[c]=a%10;
a/=10;
}
while(d--){
ba[d]=b%10;
b/=10;
}
for(x=0;x<e;x++){
ca[x]=aa[x]+ba[x]+r;
if(ca[x]>9){
ca[x]=ca[x]%10;
r=1;
}
else r=0;
}
x=0;
while(ca[x]==0)
x++;
int f=e-1;
while(e--){
m=m+ca[e]*j;
j*=10;
if(x==e)
break;
}
printf("%d\n",m);
}
return 0;
}
Well, now try giving these inputs:
2
405
794
425
796
Correct Outputs
1001
1221
Received Outputs through this program
100
122000
Does it clear your doubt?