Find the sum of product of all numbers in first array with all the numbers in second array.
Input Format
- 1st line contains 2 space separated integers N and M.
- 2nd line contains N space separated integers Ai.
- 3rd line contains M space separated integers Bi.
Output Format
- 1 single line containing only the required answer.
#include<iostream>
using namespace std;
int sum(int product)
{
static int temp = 0;
temp = temp + product;
return temp;
}
int main()
{
int N, M, result, i, j;
cin>>N>>M;
int *a1, *a2;
a1 = new int[N];
a2 = new int[M];
for(i = 0; i < N; i++)
cin>>a1[i];
for(i = 0; i < M; i++)
cin>>a2[i];
for(i = 0; i < N; i++)
{
for(j = 0; j < M; j++)
result = sum(a1[i]*a2[j]);
}
cout<<result;
return 0;
}