i cannot understand that how is the sum being calculated ??
the first array in sample input is 1 0 2 9
and the second array is 3 4 5 6 7
if we add the corresponding indexes of both the array the output would 4,4,7,15,7
then how come the output is 3,5,5,9,6 ??
Sum of two array confusion
Hello @Tanya25,
Your confusion is valid.
- The addition is taking place from last index of both index.
- Consider all elements of each array as one number.
The digits at 1s place are added first.
9+7=6 , carry=1
similarly for other places:
2+6+carry=8+1=9 , carry=0
0+5+carry=5 , carry =0
1+4+carry=5 , carry=0
3+carry=3
Hope, it would help.
If you still have doubts, feel free to ask.
Give a like if you are satisfied.
@S18ML0016 has told you the right way to proceed . Or i should say he told you the hole algorithm . But if you still didn’t understand whats going on , than read this , this might help.
Further you can catch this thing from test case given to you , that each array element holds only one digit element . So when you are adding up two array elements in new array than again it should hold one digit in each element.
You have given a no 1029 and 34567 . And user want their addition and he stored these two no in two different arrays .
Now answer won’t change , its simple addition i.e
1029
+34567
35596
Now use your programming knowledge , to get this answer
Hint : Go to the basics , How you learn basic addition !
Thank you
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.
If you still have any issue, let me know.