My 2 test cases are not correct and i dont know what those are. I have tried various test cases to try and break my program but it always gives the right answer. Is there any way of finding out the which test case to apply? also what test case should I test this program against.
the program :
#include
#include
using namespace std;
int main()
{
int i, j, n, m, a[1000], b[1000], c[1000];
cin >> n;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
cin >> m;
for (i = 0; i < m; i++)
{
cin >> b[i];
}
int maximum = max(n, m);
int k = maximum;
int carry = 0;
for (i = n - 1, j = m - 1; i >= 0 && j >= 0; i–, j–)
{
c[k] = a[i] + b[j] + carry;
if (c[k] >= 10)
{
c[k] = c[k] % 10;
carry = 1;
}
else
{
carry = 0;
}
k--;
}
while (i >= 0)
{
c[k] = a[i--] + carry;
if (c[k] >= 10)
{
c[k] = c[k] % 10;
carry = 1;
}
else
{
carry = 0;
}
k--;
}
while (j >= 0)
{
c[k] = b[j--] + carry;
if (c[k] >= 10)
{
c[k] = c[k] % 10;
carry = 1;
}
else
{
carry = 0;
}
k--;
}
if (carry == 1)
{
c[k] = 1;
}
if (c[0] == 0)
{
for (i = k + 1; i < maximum + 1; i++)
{
cout << c[i] << ", ";
}
}
else
{
for (i = k; i < maximum + 1; i++)
{
cout << c[i] << ", ";
}
}
cout << "END";
return 0;
}