I want to create the function, that takes an input of two arrays of the same size and delete all elements from the second array, that are multiples of the element(s) of the first array.
Here is my attempt:
#include <iostream>
#include <vector>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <list>
#include <algorithm>
using namespace std;
template<typename T, size_t N>
int multipl(T(&one)[N],T(&two)[N]){
for(int i = 0;i<N;++i){
for(int j = 0;j<N;++j){
if(two[j]%one[i] == 0 && one[i] !=1 && one[i] != two[j]){
two[j] = -1;
}
}
}
}
int main(){
int one[] = {2,5,2,5,5,11};
int two[] = {4,8,1,3,2,10};
multipl(one,two);
}
Basically I substituted all elements, that are multiples of the elements from first array by -1. Right noew I want to delete all elements from the array two
, which are equal to -1
. How can I do it?
With vectors it would be easier, but I want to try it with arrays in order to better understand them.