Untuk mencari nilai minimum dari suatu array, dapat digunakan fungsi Math yang ada pada delphi.
Adapun Source Code nya sebagai berikut :
NilaiMinimum.dpr
Unit1.pasprogram NilaiMinimum;usesForms,Unit1 in 'Unit1.pas' {Form1};{$R *.res}beginApplication.Initialize;Application.MainFormOnTaskbar := True;Application.CreateForm(TForm1, Form1);Application.Run;end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math;
type
TForm1 = class(TForm)
Button1: TButton;
memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
nilai : array [1..5] of integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
nilaiminimum:integer;
begin
nilaiminimum:=MinIntValue(nilai);
ShowMessage('Nilai Minimum adalah : '+inttostr(nilaiminimum));
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
nilai[1]:=5;
nilai[2]:=10;
nilai[3]:=1;
nilai[4]:=2;
nilai[5]:=11;
for I := 1 to Length(nilai) do
begin
memo1.lines.Add(inttostr(nilai[i]));
end;
end;
end.
Unit1.dfm
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 164
ClientWidth = 203
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object memo1: TMemo
Left = 8
Top = 39
Width = 185
Height = 116
TabOrder = 0
end
object Button1: TButton
Left = 8
Top = 8
Width = 185
Height = 25
Caption = 'Cari Nilai Minimum'
TabOrder = 1
OnClick = Button1Click
end
end
0 comments:
Post a Comment