Not able to solve it

if (num2>=num1)
{
k=num2;
}
else
{
k=num1;
}

not able to get the correct answer

Hey
Just add 2 nos
say 99 and 999 on paper and dont do this in mind
You will get ur answer
In case u dont then let me know :slightly_smiling_face:

Algorithm:

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 .

not able to did it . . .

Hey @rprahulpal03
Please share your code ,I will look into it :slight_smile:

#include using namespace std; int main() { int num1,num2,bigArray; cin>>num1; int Array1[num1]; for (int i = 0; i < num1; i++) { cin>>Array1[i]; } cin>>num2; int Array2[num2]; for (int i = 0; i < num2; i++) { cin>>Array2[i]; } if (num2>=num1) { bigArray=num2; } else { bigArray=num1; } int i=num1-1,j=num2-1,k=bigArray-1; int sum=0,carry=0; int SumArray[k]={0}; while(k>=0) { int d=carry; if (i>=0) { d=d+Array1[i]; } if (j>=0) { d=d+Array2[j]; } carry=d/10; d=d%10; SumArray[k]=d ; k–; i–; j–; } cout<<carry<<" “; for (int i = 0; i < bigArray; i++) { cout<<SumArray[i]<<” "; } }

Hey @rprahulpal03
please share in cb ide
Or u can refer to this https://ide.codingblocks.com/s/390097

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.