Pls check my logic is correct or not,and if yes whats the problem in code

hello @dipeshpandey2001

no it not correct.
u cannot add or print any array like this.
we use two pointers one pointer will point to ending of first array(say i) and second pointer point to ending of second array (say j) and use one carry variable that will store last generated carray (initially it will be 0).

final value= (arr1[i]+arr2[j] + carry)%10 //extracting digit
carry = (arr1[i]+arr2[j]+carry)/10 // extracting carray
i–; //move pointer to left by one position
j–;.//same here
same thing u have to repeat on remaining digits to get the final array

check this code for better clarity-

can you pls explain this partwhile(k>=0){ sum=carry; if(i>=0){ sum+=arr1[i]; } if(j>=0){ sum+=arr2[j]; } int q=sum/10; int r=sum%10; ans[k]=r; carry=q; i–; j–; k–; } if(carry!=0){ cout<<carry<<’,’<<’ β€˜; } for(int i=0;i<m;i++){ cout<<ans[i]<<’,’<<’ ';…from line 23 to 44

…

this is the explanation of same lines.

dry run on small case if it is not clear

why are we using … while(k>=0);… if(i>=0) and if(j>=0)

k is the index of final array which will fill array from last index to index 0.
hence we are using while(k>=0)

i and j are the index of given arrays , and index cannot be negative thats why we are using these conditons to ensure that we access only valid index

not able to dry run the condition,it will be clear if you tell me that way.

OKAY thanks,its clear pls send the explanation which you send in starting its not showing now.

pls reach out to technical team , this happens to u in evrry doubt it should be fixed.

email-> [email protected]

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.