0
The problem is the following: Make an algorithm that reads an array A[10]. Then remove the duplicate elements by compressing vector A. Finally insert the value zero in the last elements. Show the updated vector A.
But at last it does not execute, it gives the impression, because it does nothing and does not print the new vector on screen.
follows code below:
#include <stdio.h>
#include <string.h>
/*
Fazer um algoritmo que lê um vetor A[10].
Após, retire os elementos em duplicata compactando o vetor A.
Por fim inserir o valor zero nos últimos elementos.
Mostre o vetor A atualizado.
*/
int main(void)
{
// declara variaveis
//declara vetor unico
int vet[9];
//declara contador referente a vetor
int count;
//variavel auxiliar zero_final
int zf;
//variavel recebimento, recebe valores para testalos com o resto do array
int rec;
//variavel incremento auxiliar
int i;
//variavel compressao de array
int comp;
//variavel 'zf' (zero_final) decrementa valores para incluir zeros no final do vetor
zf=10;
/*cabeçalho inicial*/
//entra com valores
puts("\t*---------------------------*");
puts("\t| <<< ENTRE COM VALORES >>> |");
puts("\t*---------------------------*");
for(count;count<=9;count++)
scanf("%i",&vet[count]);
count=0;
//exibe valores ordenados em tela
for(count;count<=9;count++)
printf("\t VETOR[%i] = %i\n",count,vet[count]);
/*cabeçalho inicial*/
i=0;
for(count=0;count<=9;count++)
{
rec=vet[count];
while(i!=9)
{
if(rec==vet[count])
{
zf--;
comp=count;
}
for(;count<=9;count++)
{
vet[count]=vet[count++];
}
count=comp;
i++;
}
}
//inclui valor zero no fim do array
for(;count<=zf;count++)
{
vet[count]=0;
}
//imprime array em tela
for(count;count<=9;count++)
printf("\t VETOR[%i] = %i\n",count,vet[count]);
printf(" -- PRESSIONE ALGO --");
return 0;
}
Here it rotated and the output was exactly the input vector: http://ideone.com/VWBka4
– Woss
Boot
count
before the first loopfor
. In doing so, the result will be what @Andersoncarloswoss quoted.– mercador
@merchant was not made that already?
– AGenaro
ta but in fact would have to do what the statement asks, will have how to help me about?
– AGenaro
@Agenaro was not done, you just declared the variable. Another point is that your vector has size
9
, and your statement says it needs a size10
.– mercador
The problem of lack of initialization also occurs with the variable
i
.– mercador