静态数组的应用

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i, ma, mi: integer;
  a: array [1..10] of integer;                                        //静态数组类型的定义
begin
  for i := 1 to 10 do
    begin
      randomize;                                                      //随机数初始化
      a[i] := random(i * 100);                                        //小于1000的随机数
      edit1.Text := edit1.Text + inttostr(a[i]) + ' ';
    end;
  ma := a[1];
  mi := a[1];
  for i := 2 to 10 do
    begin
      if ma <= a[i] then ma := a[i];                                  //取最大值
      if mi >= a[i] then mi := a[i];                                  //取最小值
    end;
  edit2.Text := inttostr(ma);                                         //输出最大值
  edit3.Text := inttostr(mi);                                         //输出最小值
end;

procedure TForm1.Button2Click(Sender: TObject);                       //"清除"按钮
begin
  edit1.Text := '';
  edit2.Text := '';
  edit3.Text := '';
end;

end.

 

posted @ 2011-12-08 09:25  endsnow  阅读(167)  评论(0)    收藏  举报