Why is the code not working

// CPP program to sum two numbers represented two
// arrays.
#include <bits/stdc++.h>
using namespace std;

// Return sum of two number represented by the arrays.
// Size of a[] is greater than b[]. It is made sure
// be the wrapper function
void calSumUtil(int a[], int b[], int n, int m)
{
// array to store sum.
int sum[n];

int i = n - 1, j = m - 1, k = n - 1; 

int carry = 0, s = 0; 

// Until we reach beginning of array. 
// we are comparing only for second array 
// because we have already compare the size 
// of array in wrapper function. 
while (j >= 0) { 

	// find sum of corresponding element 
	// of both arrays. 
	s = a[i] + b[j] + carry; 
	sum[k] = (s % 10); 

	// Finding carry for next sum. 
	carry = s / 10; 

	k--; 
	i--; 
	j--; 
} 

// If second array size is less the first 
// array size. 
while (i >= 0) { 

	// Add carry to first array elements. 
	s = a[i] + carry; 
	sum[k] = (s % 10); 
	carry = s / 10; 

	i--; 
	k--; 
} 


// If there is carry on adding 0 index elements. 
// append 1 to total sum. 

if(carry!=0)
sum[0]=carry;
for(i=0;i<n;i++)
cout<<sum[i]<<", ";
}

// Wrapper Function
void calSum(int a[], int b[], int n, int m)
{
// Making first array which have
// greater number of element
if (n >= m)
calSumUtil(a, b, n, m);

else
	 calSumUtil(b, a, m, n); 

}

// Driven Program
int main()
{
int n,m;
cin>>n>>m;
int a[n],b[m];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<m;i++)
cin>>b[i];
calSum(a,b,n,m);
cout<<“END”;
return 0;
}

Hello @arya_31,

Share your code using Coding Blocks IDE.
The way you have send it, is introducing many syntax errors.

STEPS:

  1. Open online coding blocks IDE.
  2. Paste your code there.
  3. Save it there.
  4. Share the URL generated.

my 3rd test case is passing but all others are wrong

Hello @arya_31,

Your code is logically correct.
It should produce the correct answer.
But, it is not. Why?

Reason:
The input format of your code doesn’t match with that of the question.

Solution:
Read the question Properly.
(especially the sample input that is given in the question).

If you still have some issue finding it, feel free to ask.

Hope, this would help.
Give a like, if you are satisfied.

oh yes!i get it. Its a silly mistake i made. Thanks a lot!!

First take input m and then all the elements of the array A. then take input n and then all the element of array B.
in your question you are taking m and n as input first and then taking two array as input. please correct this and retry and let me know if still have any other doubt.

Hey @arya_31,

Please, Mark your doubt as resolved if you don’t have anything else to ask regarding this thread.