Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
994 B
1
Indexable
Never
#include <iostream>
#include <vector>

using namespace std;

vector < int >
multwoint (vector < int >&n1, vector < int >&n2)
{
  int m = n1.size ();
  int n = n2.size ();
  vector < int >result (m + n, 0);

  for (int i = m - 1; i >= 0; i--)
	{
	  for (int j = n - 1; j >= 0; j--)
		{
		  int mul = n1[i] * n2[j];
		  int sum = result[i + j + 1] + mul;
		  result[i + j + 1] = sum % 10;
		  result[i + j] += sum / 10;
		}
	}

  return result;
}

int
main ()
{
  int n, m;

  cout << "size of arr1 ";
  cin >> n;
  cout << "size of arr2 ";
  cin >> m;

  int arr1[n];
  int arr2[m];

  for (int i = 0; i < n; i++)
	{
	  cin >> arr1[i];
	}
  for (int j = 0; j < m; j++)
	{
	  cin >> arr2[j];
	}

  vector < int >v1 (n);
  for (int i = 0; i < n; i++)
	{
	  cin >> v1[i];
	}
  vector < int >v2 (m);
  for (int j = 0; j < m; j++)
	{
	  cin >> v2[j];
	}

  vector < int >result = multwoint (v1, v2);

  cout << "Answer";
for (int digit:result)
	{
	  cout << digit;
	}

  cout << endl;

  return 0;
}
Leave a Comment