output is not giving correctly,Help me out;
Where iam doing wrong…Dont tell your approach.
Tell where iam doing wrong.
Sum of arrays qstn
There are some issues in your code:-
- you are adding the arrays in reverse order which is correct but you are printing them result there only which is wrong e.g if you are last element of arr1 and last element of arr2 then the resultant value will be at last not first.
- in while loop you are not considering carry while there can be a carry from previous for loop.
- The sum can be of size maxIndex+1 if there is an carry after entire addition operation.
i didnt get first point .please explain clearly
You wrote “cout<<res[k]<<endl” in first for loop. and you are adding elements in reverse order of arrays so the first element that will be printed will be the sum of last elements of the array.
In fact you should not print elements here because you are printing them in the last for loop which is correct.
You can simple remove this cout statement.
Yaa but still the output is not coming correctly… even if removed that cout
You are declaring arr2[m] before taking input ‘m’ so proper memory is not allocated to it.
please declare arr2 after cin>>m;
and no not forget to print carry before your last for loop if it is not zero as I mentioned in point 2 and 3.
yaa.tq…but still some cases not passing.
where my code is failing?
Please make sure you are printing carry before your last for loop if it is not zero as I mentioned in point 2 and 3. as I mentioned in the previous reply. After making the mentioned changes the code should be running.