2 testcases fail why?

#include

using namespace std;

void Sum(int a[], int b[], int n, int m)
{

int sum[n]={0}; 

int i = n - 1, j = m - 1, k = 0; 

int c = 0, s = 0; 
  
 
 while(j>=0)
 {
 	s=a[i]+b[j]+c;
 	sum[k]=s%10;
 	c=s/10;
	
	
	k++;
	j--;
	i--;
		 	
 }
 
 
 while(i>=0)
 {
 	s=a[i]+c;
 	sum[k]=s%10;
 	c=s/10;
 	i--;
 	k++;
 }

 for(int i=k-1;i>=0;i--)
 {
     cout<<sum[i]<<", ";
 }

}

// Driven Program
int main()
{

int n, m;
cin>>n;

int a[10000],b[10000];

for(int i=0;i<n;i++)
{
	cin>>a[i];
}
cin>>m;
for(int i=0;i<m;i++)
{
	cin>>b[i];
}
if (n >= m) 
	 Sum(a, b, n, m); 

else
	 Sum(b, a, m, n); 
 
 
 
 cout<<"END"	;


return 0; 

}

Save your code on ide.codingblocks.com and then share its link.

Consider input:
3
5 5 5
3
5 5 5

your code’s output:
1, 1, 0, END

but the expected output is:
1, 1, 1, 0, END

Make sure your code handles different cases of carry.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.