Arrays-(sum of two arrays)

https://hack.codingblocks.com/contests/c/474/217

i am not able to handle the condition when size of two arrays are diiferent

here is the code since i am not able to save the code on coding blocks ide so i am pasting it here

#include
using namespace std;
int main() {
int n;
cin>>n;
int arr1[n];
for(int i=0;i<n;i++){
cin>>arr1[i];
}

 int m;
cin>>m;
int arr2[m];
for(int i=0;i<m;i++){
    cin>>arr2[i];
}


int len=max(n,m) ;
int arr3[len];  
int carry=0;

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

while(i>=0 && j>=0){
    int sum=arr1[i]+arr2[j]+carry;
    arr3[k]=sum%10;
    carry=sum/10;
    k--;
    i--;
    j--;
}

while(i>=0){
    int sum=arr1[i]+carry;
    arr3[k]=sum%10;
    carry=sum/10;
    k--;
    i--;
   

}

   while(j>=0){
    int sum=arr2[i]+carry;
    arr3[k]=sum%10;
    carry=sum/10;
    k--;
    j--;
   

}




for(int i=0;i<len;i++){
    cout<<arr3[i]<<", ";
}
cout<<"END";

}

Hey Kanika,
there is just a small change in your code… in while loop for j>=0 you are supposed to access arr2[j] instead of arr2[i].

while(j>=0){
int sum=arr2[j]+carry;
arr3[k]=sum%10;
carry=sum/10;
k–;
j–;
}

my bad
the code is still not working perfectly
2 test cases are still wrong

here is the code which is still not working well

https://ide.codingblocks.com/s/38547

you are not printing the correct output for some of the cases
for eg.
3
2 3 4
5
1 2 3 4 5
your code’s output is
1666479392, 1, 2, 5, 7, 9, END

but correct output for this case is
1, 2, 5, 7, 9, END

Hint is when there is no carry then you are not supposed to print 0th index of result array.

okay
thanks for the help