Sum of two arrys

#include
using namespace std;

int main() {

long long int n1,n2;

cin>>n1;

long long int arr1[n1];

for(long long int i=0;i<n1;i++)

{
	cin>>arr1[i];
}
cin>>n2;
long long int arr2[n2];
for(long long int i=0;i<n2;i++)
{
	cin>>arr2[i];
}
if(n2>n1)
{
long long int j=n1-1,i=n2-1;
     while(j>=0)
	 {
		  arr2[i]=arr2[i]+arr1[j];
		  //cout<<arr2[i]<<endl;
		  if(arr2[i]>=10)
		  {
			  arr2[i]=(arr2[i])%10;
			  arr2[i-1]+=1;
		  }
		  j--;
		  i--;
	 }
	 for(i=0;i<n2;i++)
	 {
		 cout<<arr2[i]<<", ";
	 }
	 cout<<"END";
return 0;
}
if(n2<=n1)
{
long long int j=n2-1,i=n1-1;
     while(j>=0)
	 {
		  arr1[i]=arr1[i]+arr2[j];
		  //cout<<arr2[i]<<endl;
		  if(arr1[i]>=10)
		  {
			  arr1[i]=(arr1[i])%10;
			  arr1[i-1]+=1;
		  }
		  j--;
		  i--;
	 }
	 for(i=0;i<n1;i++)
	 {
		 cout<<arr1[i]<<", ";
	 }
	 cout<<"END";
return 0;
}

}
my two test cases are going fail plzz help me to correct this code

@Pritamkumarcoder please share your code by saving it on ide.codingblocks.com

hi @Pritamkumarcoder your code is not giving correct output for cases where there is a carry in the end
eg, sample input:

5
7 0 2 9 0
5
3 4 5 6 7 

output should be:

1, 0, 4, 8, 5, 7, END

But your outpur is

0, 4, 8, 5, 7, END

thnks now my all test cases are pass

@Pritamkumarcoder please mark your doubt as resolved :slight_smile: