Showing Wrong Answer


heres my code for the problem Arrays- Sum of 2 arrays…can someone plz tell me where I am going wrong?

hi aman
check for this input
4
9 9 9 9
3
9 9 9
dubug it…

Still not working even though I resolved the problem
#include
using namespace std;

int main()
{
int N=0, M=0;
int arr1[1000]={}, arr2[1000]={}, sum_digit[1001]={};
cin>>N;
cin>>M;

//inputing the first digit beforehand so as to determine the sign of the number
int flag=0;
cin>>arr1[0];
if(arr1[0]<0)
{
	flag++;
}
if(flag==0)
{
	for(int i=1; i<N; i++)
	{
		cin>>arr1[i];
	}
}
else
{
	for(int i=1; i<N; i++)
	{
		cin>>arr1[i];
		arr1[i]*=(-1);
	}	
}

//Repeating the same process for the next number
flag=0;
cin>>arr2[0];
if(arr2[0]<0)
{
	flag++;
}
if(flag==0)
{
	for(int j=1; j<M; j++)
	{
		cin>>arr2[j];
	}
}
else
{
	for(int j=1; j<M; j++)
	{
		cin>>arr2[j];
		arr2[j]=-arr2[j];
	}
}

//------------------------main algo for the addition----------------

if(N>=M)
{
	int i=N-1, j=M-1, itr=0, carry=0;
	while((i>=0)&&(j>=0))
	{
		carry=(arr1[i]+arr2[j])/10;
		sum_digit[itr]+=(arr1[i]+arr2[j])%10;
		sum_digit[itr+1]=carry;
		--i;
		--j;
		itr++;
	}

	while(i>=0)
	{
		carry=(sum_digit[itr]+arr1[itr])/10;
		sum_digit[itr]=(sum_digit[itr]+arr1[itr])%10;
		sum_digit[itr+1]=carry;
		--i;
		++itr;
	}
	
	
	for(int ind=itr; ind>=0; ind--)
	{
		if(ind==itr && sum_digit[ind]==0)
        {
            continue;
        }
        cout<<sum_digit[ind]<<", ";
	}
	cout<<"END";
}

else
{
	int i=M-1, j=N-1, itr=0, carry=0;
	while((i>=0)&&(j>=0))
	{
		carry=(arr2[i]+arr1[j])/10;
		sum_digit[itr]+=(arr2[i]+arr1[j])%10;
		sum_digit[itr+1]=carry;
		--i;
		--j;
		itr++;
	}

	while(i>=0)
	{
		
		carry=(sum_digit[itr]+arr2[itr])/10;
		sum_digit[itr]=(sum_digit[itr]+arr2[itr])%10;
		sum_digit[itr+1]=carry;
		--i;
		++itr;
	}

	for(int ind=itr; ind>=0; ind--)
	{
		if(ind==itr && sum_digit[ind]==0)
        {
            continue;
        }
        cout<<sum_digit[ind]<<", ";
	}
	cout<<"END";
}

}

Hi aman save it code to online ide and then post the link here
It’s hard to debug if u post code like that

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.