The stopping condition for the smaller array is not clear. How to do it in the following code?

#include
using namespace std;
int main() {
int n,m, a1[1000], a2[1000];
cin>>n;
for(int i=0; i<n; i++)
{
cin>>a1[i];
}
cin>>m;
for(int i=0; i<m; i++)
{
cin>>a2[i];
}
int last = max(m,n);
int a=n-1, b=m-1;
int t[1000];
int carry=0;
for(int i=last-1; i>=0; i–)
{
t[i]= a1[a]+a2[b]+carry;
if(t[i]>9)
{
carry = t[i]/10;
t[i] = t[i]%10;
}
else{
carry =0;
}
a–;
b–;
}

for(int i = 0; i<last; i++)
{
	cout<< t[i] <<", ";
}
cout<<"END";
return 0;

}

@igarg145 hey ,stopping condition will be like this you have to traverse till smaller array first so appky this condition while(first pointer not reaches end of first array && second pointer reaches end of second array)
This loop will traverse till smaller array size ,now you have to consider the reamining big array so apply these two conditions of while separately:while(first pointer not reaches end of first array) {} ,while(second pointer not reaches end of second array) and apply same logic of sum that you have applied in above soln.

for the first while loop we should as you said we have to iterate till end but we should iterate from end to start for the sum?

@igarg145 hey yes we have to iterate from back or you may first reverse the array and than iterate from starting and apply above conditions.

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.