#include <stdio.h>
int main ()
{
int cont=0, l, c, i, j, m, n, mat[10][10], vet[100], h=0;
// leitura das dimensoes da matriz
scanf ("%d %d" ,&l ,&c);
//caso as dimensoes nao sejam do tamanho desejado pelo exercicio
if (l<=0||l>10||c<=0||c>10){
printf("dimensao invalida\n");
return 0;
}
else
{
//leitura dos elementos da matriz
for (i=0;i<l;i++)
{
for (j=0;j<c;j++)
{
scanf("%d" ,&mat[i][j]);
}
}
//transformacao da matriz em um vetor
for (i=0;i<l;i++)
{
for (j=0;j<c;j++)
{
vet[h] = mat[i][j];
h = h + 1;
}
}
//comparacao de elemento por elemento
for (i = 0; i < (l*c); i++)
{
for (j = i + 1; j < (l*c); j++)
{
if (vet[i] != vet[j] && i!=j)
{
printf("%d" ,vet[i]);
cont++;
}
}
}
printf(" %d" ,cont);
}
return 0;
}
I know the problem is in the comparison of arrays, however my question is: Do I have to use a function that compares the elements of my vector and consequently use a pointer? Can I make this comparison with the elements of my array without converting it to a vector?