Arrays sum of two arrays

getting testcase 1 and 2 wrong.
Is there any better way to do it please tell that also.

@Rakshitgarg99 In this question you just have to take the input of the two arrays and pass them to a function. In that function, you need to add the values of the two arrays index wise like in the given example,
Arr1 = [1 0 2 9]
Arr2 = [3 4 5 6 7]
So, let num1 = 1029 and num2 = 34567
Perform normal addition on num1 and num2
1029+34567 = 35596
Return this new number to main and print in the given output format like 3, 5, 5, 9, 6, END.
Try to solve this on your own and come up with a logic.


i forget to attach the file

Sample Input
4
1 0 2 9
5
3 4 5 6 7
Sample Output
3, 5, 5, 9, 6, END

Your code is not giving correct output for this case. Dry run and check for this case.
Also for cases when the two arrays have different sizes your code is not handling correctly.
For case:
3
5
3
5 5 5

Your O/P:
8, 5, 5, 3, 5, END

Which is incorrect.

i am getting correct answers on my system and onlinegdb.com

Please save the save code on ide.codingblocks.com and share its link.

Hey…still the same issue as i said earlier. Try to dry run your code with different cases.
For case:
3
5
3
5 5 5

Your O/P:
8, 5, 5, 3, 5, END

Which is incorrect.

If you are facing problem with the approach the refer this:

1.Traverse both the arrays simultaneously from the end until we reach the 0th index of either of the array.
2.While traversing each element of array, add an element from both arrays and carry from the previous sum.
…………2.1 Store the unit digit of the sum(obtained by doing - sum%10) in the ans array.
…………2.2 forward carry(obtained by doing - sum/10) for the next index sum.
3.After the loop ends we are left with one of the arrays and the carry.
4.We will now repeat step 2 but now for one array which is left after the loop.
5.If carry !=0 then store the carry in the 0th index of ans array.
6.Print the ans array

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.