delphi编程
- 提问者网友:像風在裏
- 2021-04-29 09:24
- 五星知识达人网友:痴妹与他
- 2021-04-29 10:31
楼上抄袭的额
我附刚做的原码和截图
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
inum: array[0..9] of Byte;
MaxNum, MinNum: Byte;
AverageNum: Double;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: Byte;
begin
Randomize;
for i := Low(inum) to High(inum) do
begin
if i in [0..4] then
begin
inum[i] := Random(100) + 1;
Canvas.TextOut((i + 1) * 30, 10, IntToStr(inum[i]));
end;
if i in [5..9] then
begin
inum[i] := Random(100) + 1;
Canvas.TextOut((i - 5 + 1) * 30, 30, IntToStr(inum[i]));
end;
end;
MaxNum := inum[Low(inum)];
MinNum := inum[Low(inum)];
AverageNum := 0;
for i := Low(inum) to High(inum) do
begin
if inum[i] > MaxNum then
MaxNum := inum[i];
if inum[i] < MinNum then
MinNum := inum[i];
AverageNum := AverageNum + inum[i];
end;
AverageNum := AverageNum / 10;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('最大值 -> ' + IntToStr(MaxNum));
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage('最小值 -> ' + IntToStr(MinNum));
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessageFmt('%.1f', [AverageNum]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := '产生随机数';
Button2.Caption := '最大数';
Button3.Caption := '最小数';
Button4.Caption := '平均数';
end;
end.
- 1楼网友:有你哪都是故乡
- 2021-04-29 12:01