1
In the code below the intention is to intersect two vectors, but when it does not check if the value is 0
in that passage
if(vet1[i] == vet2[j])
{
n = vet1[i];
}else
{
C[i] = '\0';
}
I check if the values are equal for the intersection, but when I get to the printf
for(int i=0; i < 5;i++)
{
if(C[i] != '\0')
printf("os dois vetores tem em comum %d.\n", C[i]);
}
How do I verify that there is an intersection of the number 0
?
I used the \0
so that when there is no intersection it adheres to a null value.
Entire code below:
#include <iostream>
int main()
{
int n;
int vet1[5]= {1,8,9,4,5}, vet2[8] = {8,3,6,5,4,3,2,1}, C[5];
for(int i=0; i < 5;i++)
{
n=0;
for(int j=0;j < 8;j++)
{
// verifica se na posiçao i o vetor é
if(vet1[i] == vet2[j])
{
n = vet1[i];
}else
{
C[i] = '\0';
}
}
C[i] = n;
}
for(int i=0; i < 5;i++)
{
if(C[i] != '\0')
printf("os dois vetores tem em comum %d.\n", C[i]);
}
for
return 0;
}