Fórum Como saber O maior; Menor e o meio #238190
17/06/2004
0
EX: valor classificação
5 Maior
3 Meio(intermediario)
1 Menor
Lembrando q esses valores mudaram aleatoriamente
Rodrigovollo
Curtir tópico
+ 0Posts
17/06/2004
Xanatos
v1:= RandomRange(1,100); v2:= RandomRange(1,100); v3:= RandomRange(1,100); if (v1>v2) then begin if (v1>v3) then begin if (v2>v3) then begin Maior:=v1; Menor:=v3; Meio:=v2; end else begin Maior:=v1; Menor:=v2; Meio:=v3; end end else begin if (v2<v3) then begin Menor:=v2; Meio:=v1; Maior:=v3; end else begin Menor:=v3; Meio:=v1; Maior:=v2; end end; end else if (v1<v3) then begin if (v2<v3) then begin Menor:= v1; Maior:=v3; Meio:= v2; end else begin Menor:= v1; Maior:=v2; Meio:= v3; end; end else begin Maior:= v2; Meio:= v1; Menor:= v3; end; showmessage(format(´Menor = ¬d Meio = ¬d Maior ¬d´,[Menor,Meio,Maior]));
:lol:
Gostei + 0
17/06/2004
Thiago Vidal
A rotina PegaMaiorMenor pode ser aproveitada em outros sistemas, basta passar os 3 valors em qualquer ordem que seram retornados na ordem decrescente (Maior -> Menor).
program teste;
{$APPTYPE CONSOLE}
uses
SysUtils, Math;
procedure PegaMaiorMenor(var Maior, Meio, Menor: Word);
var
A, B, C: Byte;
begin
A := Maior;
B := Meio;
C := Menor;
Maior := Max(A, Max(B, C));
Menor := Min(A, Min(B, C));
if (Maior <> A) and (Menor <> A) then
Meio := A
else if (Maior <> B) and (Menor <> B) then
Meio := B
else
Meio := C;
end;
var
N1, N2, N3: Word;
c: char;
begin
repeat
Randomize;
N1 := Random(High(Word));
N2 := Random(High(Word));
N3 := Random(High(Word));
PegaMaiorMenor(N1, N2, N3);
WriteLN(´Maior: ´ + IntToStr(N1));
WriteLN(´Intermed: ´ + IntToStr(N2));
WriteLN(´Menor: ´ + IntToStr(N3));
ReadLN(c);
WriteLN;
until (c = ´x´);
end.
Espero ter ajudado.
Gostei + 0
17/06/2004
Thiago Vidal
Também estava com um problema parecido, e agora acho que consegui resolve-lo. Espero que voce consiga também.
procedure Sort(var A: array of Integer); var I, J, T: Integer; begin for I := Low(A) to High(A) - 1 do for J := High(A) downto I + 1 do if A[I] > A[J] then begin T := A[I]; A[I] := A[J]; A[J] := T; end; end;
Gostei + 0
17/06/2004
Aroldo Zanela
Acho que a forma mais simples é esta:
var Lista: TStringList; begin Lista := TStringList.Create; Lista.Add(´5 - Maior´); Lista.Add(´1 - Menor´); Lista.Add(´3 - Meio´); Lista.Sort; ShowMessage(Lista.Strings[2]); // Maior ShowMessage(Lista.Strings[1]); // Meio ShowMessage(Lista.Strings[0]); // Menor Lista.Free; end;
Gostei + 0
17/06/2004
Rodrigovollo
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)