
30.10.2010, 08:48
|
Прохожий
|
|
Регистрация: 01.10.2010
Сообщения: 4
Репутация: 10
|
|
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
const n=10;
type y = array of Real;
type
TForm1 = class(TForm)
strngrd1: TStringGrid;
btn2: TButton;
btn3: TButton;
btn4: TButton;
edt1: TEdit;
procedure btn2Click(Sender: TObject);
procedure btn4Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x :y;
i : Integer;
s : Real;
implementation
{$R *.dfm}
procedure TForm1.btn2Click(Sender: TObject);
begin
for i := 0 to n-1 do
x[i] := StrToFloat (Strngrd1.Cells[i,0]) ;
end;
procedure TForm1.btn4Click(Sender: TObject);
begin
edt1.Text := '';
end;
procedure TForm1.btn3Click(Sender: TObject);
var nmin, nmax : Integer;
min, max : Real;
begin
s := 0;
min := x[0];
nmin := 0;
max := x[0];
nmax := 0;
for i := 1 to n-1 do
begin if min>x[i] then begin min := x[i]; nmin := i; end;
if max<x[i] then begin max := x[i]; nmax := i; end;
end;
if nmin<nmax then begin
for i := nmin to nmax-1 do
s := s+x[i];
end
else begin
for i := nmax to nmin-1 do
s := s+x[i];
end;
edt1.Text := FloatToStr(s);
end;
end.
первая задача, помогите найти ошибку
|