Check for duplicate numbers and delete them

-2

Enter the data in VET, and then check the repeated numbers, and leave in the VET1 only the numbers that are not repeated, but not able to do that last part at all, follow the code I have done so far: / p>

#include <stdio.h>
#include <stdlib.h>
#define T 3

int main()
{
    int vet[T];
    int vet1[T];
    int i, j, achou = 0, quant = 0;

    printf("Digitar os numeros:");
    for(i = 0; i < T; i++)
    {
        scanf("%d", &vet[i]);
    }
    for(i = 0; i < T; i++)
    {

        for(j = 0; j < quant; j++)
        {
            achou = 0;
            if(vet[i] == vet1[j])
            {
                achou = 1;
                break;
            }
            if(achou == 0)
            {
                vet1[quant] = vet[i];
                quant ++;
            }
        }

    }
    for (i = 0; i <= quant; i++)
    {
        printf("%d", vet[i]);
    }
    return 0;
}
    
asked by anonymous 04.11.2018 / 02:04

1 answer

0

I was able to:

#include <stdio.h>
#include <stdlib.h>
#define T 5

int main(){
int vet[T];
int vet1[T];
int i, j, n= 0;

printf("Digitar os numeros:");
for(i = 0; i < T; i++)
    {
        scanf("%d", &vet[i]);
    }
    for(i = 0; i < T; i++)
    {
        for( j = 0; j < n; j++ )
        {
            if( vet[i] == vet1[j] )
                break;
        }

        if( j == n )
        {
            vet1[n] = vet[i];
            n++;
        }
      }
    for (i = 0; i <n; i++)
    {
        printf("%d", vet1[i]);
    }
    return 0;
}
    
04.11.2018 / 16:32