unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  close;
end;

var

   C:array of real;
   i,n,m:Integer;
procedure TForm1.Button3Click(Sender: TObject);

begin
    Edit4.Text:='';
    if Edit1.text='' then
                                 begin
                                 ShowMessage('Введите число n');
                                 Exit;
                                 end;

    n:=StrToInt(Edit1.text);
    SetLength(C,n);

    Randomize;
    for i:=0 to n-1 do
                      begin
                        C[i]:=Random(10)-5;

                       Edit4.Text:=Edit4.text+FloatToStr(C[i])+' ';
                      end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var     CP:integer;
        W:Real;
begin
    if Edit4.text='' then
                                 begin
                                 ShowMessage('Не сгенерирован ряд чисел');
                                 Exit;
                                 end;


                      W:=C[i];
                      i:=2;
                      While i< n-1 do
                                      begin
                                      W:=C[i];
                                      C[i]:=(C[i-1]+C[i-2])/2;
                                      C[i-1]:=(W+C[i-2])/2;
                                      i:=I+3
                                   end;
                     for i:=0 to n-1   do
                     begin
                          Edit3.text:=Edit3.text+FloatToStr(C[i])+' ';
                     end;
end;

end.
