Unable to find error in the algorithm

#include
using namespace std;

void Sum(int a[1000],int m,int b[1000],int n)
{
int d,s=0,c=0,i;
for(i=m-1;i>=0;i–)
{
d=i-m+n;
if(d>=0){
s=a[i]+b[d]+c;
a[i]=s%10;
c=s/10;
}
else{
s=a[i]+c;
a[i]=s%10;
c=s/10;
}
}
if(c==0){
for(i=0;i<m;i++)
cout<<a[i]<<", β€œ;
}
else{
cout<<c<<” ,";
for(i=0;i<m;i++)
cout<<a[i]<<", ";
}
cout<<β€œEND”<<endl;
}

int main()
{
int a[1000],m,b[1000],n,i;
cin>>m;
for(i=0;i<m;i++)
cin>>a[i];
cin>>n;
for(i=0;i<n;i++)
cin>>b[i];

m>n?Sum(a,m,b,n):Sum(b,n,a,m);

}

Hello @ckaushik1799 what is the problem that you are facing?
i am checking your code:

Out of 4 cases, only 2 are getting passed.
I myself tried various inputs and they seemed correct to me.
don’t know why 2 are getting failed ?

@ckaushik1799 PLEASE WAIT.

hey @ckaushik1799 think when both m and n are equal.

i think you have not prepared anything for that case.

i have prepared for m=n case.
You may also check by running it

hey @ckaushik1799
see the updated code:


if you have any doubt you can ask here:
Happy Learning!!

1 Like

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.