Sum of two array

// this is my new code and it shows right output for 1 ,9 and 1,9 but again 2 test cases not running
#include
using namespace std;
int sum(int a[1000],int b[1000],int n,int m)
{
int i,j,k,q,w,g,z=0;
int c[10000];
if(n>m)
{
k=n-m;
for(i=m-1+k;i>=k;i–)
{
b[i]=b[i-k];
}
for(i=0;i<k;i++)
{
b[i]=0;
}
m+=k;
}
if(m>n)
{
k=m-n;
for(i=n-1+k;i>=k;i–)
{
a[i]=a[i-k];
}
for(i=0;i<k;i++)
{
a[i]=0;
}
n+=k;
}
if(m==n)
{
w=0;
for(i=n-1;i>=0;i–)
{
if(i==0)
{
q=a[i]+b[i];
if(q>9)
{
for(g=n;g>=1;g–)
{
c[n]=c[n-1];
}
c[1]=(q%10)+w;
w=q/10;
c[0]=w;
z=1;
}
else
{
c[i]=q+w;
}

		}
		else
		{
		q=(a[i]+b[i])%10;
		c[i]=q+w;
		
		}
		w=(a[i]+b[i])/10;

	}
	if(z==0)
	for(i=0;i<n;i++)
	{
		cout<<c[i]<<", ";
	}
	else
	for(i=0;i<=n;i++)
	{
		cout<<c[i]<<", ";
	}

}
cout<<"END";
return 0;

}
int main() {
int i,j,s,n,m;
int a[1000],b[1000];
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cin>>m;
for(i=0;i<m;i++)
{
cin>>b[i];
}
sum(a,b,n,m);
return 0;
}

hello @lovish2552
3
9 9 9
3
9 9 9

check ur code output for above test case

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.