我有两个数组,需要对它们进行比较。将P[p]
中的每个元素与child1[q]
中的每个元素进行比较。如果不匹配,那么P[p]
中的该元素将被存储在另一个新阵列中。我应该在哪里保留cout
声明,以便将不匹配的数字转换为另一个数组。比较两个数组并获得差异答案到另一个数组中
谢谢。
int P[ ]={3,7,6,5,2,4,1,8};
int child1[ ]={3,7,6,5,8,6,7,2};
// getting the missing numbers
for(int p=0;p< r;p++) // here r is size of the array i.e.8
{
for (int q=0;q< r;q++)
{
if (child1[q]==P[p])
{
p++;
}
q++;
}
cout<< P[p]; // i have a problem here.where should i keep this statement for getting the mismatched number into an another array
int M[p]=P[p]; //the result must be M[2]={4,1}
}
'如果(child1 [Q] = P [P])'的分配,没有比较,在'if'语句后面有';'。 – fasked
你不需要2'for'循环,你可以使用1. – user2485710
这听起来像是集合交集的逆,不是吗? (换句话说,'(a U b)\(a^b)'('^'是我找到的最好的运算符:)) – Manu343726