Wrong Test Cases

code:

using namespace std;
#include
#include
int main()
{
int n,m,carry;

//first Digit
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

//Second Digit
cin>>m;
int b[m];
for(int i=0;i<m;i++)
cin>>b[i];

//Containing Sum
int k=max(n,m);
int sum=0,p=1;	//for extra carry i have added 1

for(int i=0;i<min(n,m);i++)
{
	int total=a[n-1-i]+b[m-1-i]+carry;
	sum+=(total%10)*p;
	carry=total/10;	//why sum[i+1] becoz for last carry, sum array has extra capacity of 1
	p*=10;
}

if(n>m)
{
	for(int i=n-m-1;i>=0;i--)
	{
		int total=a[i]+carry;
		sum+=(total%10)*p;
		carry=total/10;
		p*=10;
	}
}

else
{
	for(int i=m-n-1;i>=0;i--)
	{
		int total=b[i]+carry;
		sum+=(total%10)*p;
		carry=total/10;
		p*=10;
	}
}
sum+=carry*p;
string s=to_string(sum);

for(int i=0;i<s.length();i++)
cout<<s[i]<<", ";
cout<<"END";

}

please share code in cb IDE hard to debug unformatted code

from where and how i will share

go to this link


paste ur code
then click the save button
then share the link

bro u have provideed 3 codes which one should i debug for u ?
please check if the
input
1
9
2
9 9
gives o/p
1, 0, 8, END

which one u feel easy to debug plz do, i am not getting my mistake

the value of sum variable is wrong
u can simply use a vector to store total%10 at each step
in the end if the carry is generated u can add it to the vector
now just reverse the vector
print it