0
My function needs to find the line where the first occurrence of a vector occurs within a matrix and return its line. But it is always returning the wrong line, my logic is wrong?
My job:
int busca( int mat[][MAX],int n, int m, int N, float vetor[])
{
int i,j,k,aux;
for(k=0;k<N;k++)
{
printf("Informe o valor do %d vetor:", k+1 ); // le o vetor
scanf("%f",&vetor[k]);
}
for (i =0; i < n ;i ++)
{
for ( j = 0; j < m ;j ++)
{
printf ("Digite mat [%d][%d]: ",i , j) ; //le a matriz
scanf ("%d",&mat [i][j]) ;
}
}
//aqui seria a logica pra achar o elemento igual
for(i=0; i<n;i++)
{
for(j=0;j<m;j++)
{
if(mat[i][j] == vetor[k])
{
return i;
}
}
}
if (i>=0)
printf(" A primeira ocorrencia do vetor eh na linha %d\n.",i-1 );
else
return -1;
}