Fórum Valor repetido em um Array #273132
18/03/2005
0
Como posso fazer para verificar se há valores iguais em um array de inteiros?
Exemplo:
VNumeros : array [1..10] of integer;
VNumeros[1] := 3;
VNumeros[2] := 5;
VNumeros[3] := 4;
VNumeros[4] := 8;
...
VNumeros[10] := 5;
Nesse exemplo hipotético, que rotina utilizaria para descobrir que existem dois itens do array com o mesmo valor?
Obrigado.
Exemplo:
VNumeros : array [1..10] of integer;
VNumeros[1] := 3;
VNumeros[2] := 5;
VNumeros[3] := 4;
VNumeros[4] := 8;
...
VNumeros[10] := 5;
Nesse exemplo hipotético, que rotina utilizaria para descobrir que existem dois itens do array com o mesmo valor?
Obrigado.
Valdirdill
Curtir tópico
+ 0
Responder
Posts
18/03/2005
Rômulo Barros
procedure TForm1.Button1Click(Sender: TObject); Var MeuArray : Array [1..10] Of Integer; C,J : Byte; begin MeuArray[1] := 1 ; MeuArray[2] := 2 ; MeuArray[3] := 1 ; MeuArray[4] := 4 ; MeuArray[5] := 5 ; MeuArray[6] := 6 ; MeuArray[7] := 7 ; MeuArray[8] := 8 ; MeuArray[9] := 9 ; MeuArray[10] := 10; For C := 1 To 10 Do Begin For J := 1 To 10 Do Begin If(J <> C)Then Begin If(MeuArray[C] = MeuArray[J])Then Begin ShowMessage(´Valores iguais no array´); End; End; End; End; end;
_____________________________________________
[b:48c3c74585][color=blue:48c3c74585]Utilize a Ferramenta de Pesquisa do Fórum[/color:48c3c74585][/b:48c3c74585]
Pesquisar pelos termos
_____________________________________________
[b:48c3c74585]Veja como[url=http://forum.clubedelphi.net/viewtopic.php?t=16976] OBTER RESPOSTAR RÁPIDAS[/url][/b:48c3c74585]
[b:48c3c74585]Veja as novas [url=http://forum.clubedelphi.net/viewtopic.php?t=59817]MUDANÇAS NA ESTRUTURA[/url] do site[/b:48c3c74585]
[b:48c3c74585]Leia sempre as [url=http://forum.clubedelphi.net/viewtopic.php?t=6689]REGRAS DE CONDUTA[/url][/b:48c3c74585]
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)