2 test cases are not passing
can you help me find out why?
Ques : Arrays - sum of two array
look at the test case i have saved here, the problem is you are accessing some wrong indices in a lot of places
for example if m and n are equal
int s[m1]={0};
s[m1-1]=(a[m1-1]+b[m1-1])%10;
this accesses s[-1] which is clearly a wrong access
so the correct solution would be
maintain the following variables
i, j, carry sum
i - to iterate over first array initialised to m-1
j - to iterate over second array initialised to n-1
carry and sum initialised to zero
now while(i>=0 && j>=0)
{
temp = 0;
sum = sum*10
temp= (a1[i] + a2[j] + carry)%10;
sum += sum + temp;
carry = (a1[i] + a2[j] + carry)/10;
}
at the end if j>=0 do the but just take a2[j] or if i>=0 just take a1[i]
finally print digits of sum
m1 is max of size of two arrays not the difference between size of two arrays.
Can you please help me finding error in my code?
okay, m1 can be greater can x and y, that is the mistake
you can follow the approach that i mentioned above
@J20APPPP0005 if your doubt is solved, please mark it as resolved