Given two arrays ar1
and ar2
, how can we find sum of two elements from two arrays such that indices are not same and their sum is minimum?
However, I have written the following, but I am not sure regarding storing the sum in a temporary variable and comparing the sum with the sum in the immediately next pass:
int twinArrays(int ar1_size, int* ar1, int ar2_size, int* ar2)
{
int temp;
for(int i = 0; i < ar1_size;i++)
{
for(int j=0; j < ar2_size; j++) {
int sum=0;
if( i != j)
sum = ar1[i] + ar2[j];
}
}
return temp;
}
}
Suggestions in C would be helpful.