Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki
Función para obtener el mínimo y el máximo de un array de números - Delphi
Lenguaje de programación Borland Delphi


Dos funciones Delphi para obtener el mínimo y el máximo de un array de números:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    bObtener: TButton;
    txtValores: TEdit;
    Label1: TLabel;
    lMinimo: TLabel;
    lMaximo: TLabel;
    Label4: TLabel;
    procedure bObtenerClick(Sender: TObject);
  private
{ Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function buscarMaximo (Arr: array of Integer) : Integer;
var
 i, M : Integer;
begin
  M := Arr[Low(Arr)];
  for i := 1 to High(Arr) do
    if Arr[i] > M then
      M := Arr[i];
  Result := M;
end;

function buscarMinimo(Arr: array of Integer) : Integer;
var
  i, M : Integer;
begin
  M := Arr[Low(Arr)];
  for i := 1 to High(Arr) do
    if Arr[i] < M then
      M := Arr[i];
  Result := M;
end;

procedure TForm1.bObtenerClick(Sender: TObject);
var
  i, Max, Min: Integer;
  Arr : array[0..9] of Integer;
  Num, valores : string;
begin
  i := 0;
  valores := txtValores.Text;
  repeat
    Num := Copy(valores, 1, Pos(" ", valores) - 1);
    Delete(valores, 1, Pos(" ", valores));
    Arr[i]:=StrToInt(Num);
    Inc(i);
  until i = 9;
  Arr[9] := StrToInt(valores);

  Max := buscarMaximo(Arr);
  Min := buscarMinimo(Arr);
  lMinimo.Caption := "Mínimo = " + IntToStr(Min);
  lMaximo.Caption := "Máximo = " + IntToStr(Max);
end;

end.




Publicado el: 2006-03-05

Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A