Following is my code
“#include iostream”
“#include vector”
“#include algorithm”
using namespace std;
void fun(vector a, vector b, int n, int m)
{
for (int i = 0; i < m; i++)
{
int curr_sum = a[i] + b[i];
if (curr_sum >= 10)
{
a[i] = curr_sum % 10;
a[i + 1] += curr_sum / 10;
}
else
{
a[i] = curr_sum;
}
}
if (a[n - 1] >= 10)
{
int x = a[n - 1];
a.pop_back();
int temp = x % 10;
a.push_back(temp);
temp = x / 10;
a.push_back(temp);
reverse(a.begin(), a.end());
}
for (int i = 0; i < a.size(); i++)
{
cout << a[i] << ", ";
}
cout << "END";
}
int main()
{
vector a;
int n, num;
cin >> n;
for (int i = n - 1; i >= 0; i–)
{
cin >> num;
a.push_back(num);
}
reverse(a.begin(), a.end());
vector<int> b;
int m;
cin >> m;
for (int i = m - 1; i >= 0; i--)
{
cin >> num;
b.push_back(num);
}
reverse(b.begin(), b.end());
if (n > m)
{
fun(a, b, n, m);
}
else{
fun(b, a, m, n);
}
return 0;
}