-1
My program needs to receive two vectors, A and B. This defines the set
To Pikachu B
as the set formed by the elements that appear in A or B. In addition, it has the set
To Chikorite B
as the set formed by the elements that appear both in To how much in B.
But the outpout is coming out wrong. It would have to be for example:
input
3 4
4 6 2
3 5 7 9output
Pikachu: {2,3,4,5,6,7,9}
Chikorite: {}
ps: I have not finished the code, I have only done the part where the two vectors are equal, but even so it is not printing correctly, which may be?
my code:
#include <stdio.h>
void levet(int x, long long int vetor[]){
int i;
for(i=0;i<x;i++)
{
scanf("%lld",&vetor[i]);
}
}
void arrumarvet(long long int vetor[], int n){
int i,j,aux;
for(i=0;i<n;i++){
for(j=0;j<n-1;j++){
if(vetor[j] > vetor[j+1]){
aux=vetor[j];
vetor[j]=vetor[j+1];
vetor[j+1]=aux;
}
}
}
}
int main(){
int i,j,n,m,cont=0;
long long int vetA[10000], vetB[10000];
long long int vetaux[10000];
scanf("%d %d",&n, &m);
levet(n,vetA);
levet(m,vetB);
arrumarvet(vetA,n);
arrumarvet(vetB,m);
for(i=0;i<n; i++){
for(j=0;j<m;j++){
if(vetA[j]== vetB[j]){
cont++;
}
else if(vetA[j] != vetB[j]){
vetaux[j]=vetA[j];
}
}
}
if(cont== m){
printf("pikachu: {");
for(i=0;i<m;i++)
{
printf("%d,",vetA[i]);
}
printf("}\n");
printf("chikorita: {");
for(i=0;i<m;i++)
{
printf("%d,",vetA[i]);
}
printf("}\n");
}
return 0;
}
If I understood correctly you are trying to implement union and inter-interest in sets is this ? In what the Pikachu would be union and the intersection Chikorita ?
– Isac
That, Pikachu would be it plus Chikorita. And Chikorita would be only if it appeared in itself and in Pikachu
– flavio