I am unable to think the logic

Please give some directions for that. I can’t think of a brute force solution to this problem

hello @atreyyash

how we add numbers in math?
we first add right most digits of both the numbers and move carray forward if generated
then second right most digits including carry from last addition
and we repeat this procedure till we reach extreme left.

u just have to simulate the same thing.

how to pass the carry, please tell for this also

just store previous carray in some variable and use it in ur current digit addition and then update ur previous carry

refer this for clarity->
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 .

Please check :: https://ide.codingblocks.com/s/433005


	for(int i=n;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			int tmp = a[i] + b[j];
			if(tmp > 9)
			{
				tmp = tmp / 10;
			}
			sum[i] = tmp;
		}
	}

this is wrong, u have to simultaneously iterate for i and j (here for every single i , u are iterating to each j which is wrong)

so use while loop for refrence check code i shared ibove.

sir do we need to call the function or not?

which function . . . .? sumArray?

public static void arraySum

that code is in java and i shared with u for refrence purpose.

yeah u have to make similar function and then call it from main .

here is ur updated code->

please check my code https://ide.codingblocks.com/s/433005

check now->

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.