unit Unit1;

interface

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

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

var
  Form1: TForm1;
  r,i,n,m:longint;
  s:real;
  a:string;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
n:=random(20);
m:=random(n)+5;
while m<=n do m:=random(n)+5;
s:=0;
for i:=n to m do s:=s+i;
s:=s/(m-n+1);
label1.Caption:=inttostr(n);
label2.Caption:=inttostr(m);
r:=0;
showmessage(' Найди среднее арифметическое чисел : от меньшего до большего, включая их ');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if abs(StrToFloat(edit1.Text)-s)<0.01 then begin
 ShowMessage('Верно! ');
 n:=random(20);
 m:=random(n)+5;
 while m<=n do m:=random(100);
 s:=0;
 for i:=n to m do s:=s+i;
 s:=s/(m-n+1);
 label1.Caption:=inttostr(n);
 edit1.Text:='';
 label2.Caption:=inttostr(m)
end
else begin
 r:=r+1;
 edit1.Text:='';
 ShowMessage('Неверно ');
 form1.ActiveControl:=Edit1;
end;

end;

end.
