All test case are not passed

Only two test case are passed why not all

@mayurjhode55 size of ‘z’ array shoud be k+1,
for example
n=9321
m=831
ans= 10152
because of carry

i increased the size of array but it is not passing all the test cases

Please share your updated code. And make sure that you have considered all cases. Then only you’ll learn to solve complex problems.

#include<bits/stdc++.h> using namespace std; int main(){ int n,m,sum=0,s,t; cin>>n; int a[1000]={0}; for(int i=n-1;i>=0;i–){ cin>>a[i]; } cin>>m; int b[1000]={0}; for(int i=m-1;i>=0;i–){ cin>>b[i]; } int k=max(m,n); int z[k+1]; for(int i=0;i<k+1;i++){ s=a[i]+b[i]+sum; z[i]=s%10; sum=s/10; } for(int i=k;i>=0;i–){ if(i!=k){ cout<<z[i]<<", "; } } cout<<“END”; return 0; }

@mayurjhode55 How will I be able to read this if you would write it so compact

#include <bits/stdc++.h> using namespace std; int main() { int n,t,m,sum=0,s; cin>>n; int a[1000]={0}; for(int i=n-1;i>=0;i–){ cin>>a[i]; } cin>>m; int b[1000]={0}; for(int i=m-1;i>=0;i–){ cin>>b[i]; } t=max(m,n); int c[t+1]; for(int i=0;i<t+1;i++){ s=a[i]+b[i]+sum; c[i]=s%10; sum=s/10; } for(int i=t;i>=0;i–){ cout<<c[i]<<", "; } cout<<“END”; return 0; }

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t,m,sum=0,s;
cin>>n;
int a[1000]={0};
for(int i=n-1;i>=0;i–){
cin>>a[i];
}
cin>>m;
int b[1000]={0};
for(int i=m-1;i>=0;i–){
cin>>b[i];
}
t=max(m,n);
int c[t+1];
for(int i=0;i<t+1;i++){
s=a[i]+b[i]+sum;
c[i]=s%10;
sum=s/10;
}
for(int i=t;i>=0;i–){

    cout<<c[i]<<", ";

}
cout<<"END";
return 0;

}

Now tell me ,why all test cases are not passed

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.