For a program that I am writing for fun (one that finds the Greatest Common Denominator and the Lowest Common Multiple); I’ve come across some difficulty.
I have two arrays that contain 14 numbers. To find the Lowest Common Multiple of all the numbers, I need to compare every element in each array. So far I’ve got this test:
for(int i = 0; i < 14; i++)
{
for(int j = 0; j < 14; j++)
{
if(array[i] == arr[j])
{
tesst[i] = array[i];
}
}
}
The thing is, there are endless amounts of things that could go wrong with:
tesst[i] = array[i]
Can anyone help me sort out my little algorithm?
Sort each of your input arrays, then get the intersection using std::set_intersection.