Error finding matching numbers

-1

I'm trying to make an issue that if equal values will be counted with a single, only I'm not managing to mark as a single value.

question link

#include <stdio.h>

int main(int argc, char** argv)
{
   int a, m, i, j, cont = 0;
   while(1)
   {
      scanf("%d %d", &a, &m);
      if(a == 0 && m == 0)
        break;
      int vetor[m], verifica[m];
      for(i = 0; i < m; i++)
      {
        verifica[i] = 0;
      }
      for(i = 0; i < m; i++)
      {
        scanf("%d", &vetor[i]);
      }
      for(i = 0; i < m; i++)
      {
        for(j = 0; j < m; j++)
        {
            if(vetor[i] == vetor[j] && verifica[i] != 1 && verifica[j] != 1)
             {
                 cont++;
                 verifica[i] = 1;
                 verifica[j] = 1;
             }
         }
       }

     printf("%d\n", cont);
   }
   return 0;
} 
    
asked by anonymous 18.01.2018 / 16:56

1 answer

0

I believe this is what you would like:

int main(int argc, char** argv)
{
   int m, i, j, cont = 0;
   int vetor[100], verifica[100];

      scanf("%d", &m);
    if(m != 0) { 
        for(i = 0; i < m; i++)
            verifica[i] = 0;

        for(i = 0; i < m; i++)
            scanf("%d", &vetor[i]);

        for(i = 0; i < m; i++)
            for(j = i + 1; j < m; j++)
                if(vetor[i] == vetor[j] && verifica[j] != 1 && verifica[i] != 1) {
                    cont++;
                    verifica[i] = 1;
                    verifica[j] = 1;
                }   
     } 
     for (i = 0; i < m; i++)
        printf("%d - %d\n", vetor[i], verifica[i]);


     printf("Total: %d\n", cont);
   return 0;
}

Your biggest problem was the definition of the vector (the size in c needs to be fixed) and the variable "a" that was not used. I put a for to show how the vectors were.

    
22.01.2018 / 22:18