Вот, теперь работает первая часть, работаю над вторым вопросом в задании.
Код:
unit lab;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var a:array[1..10] of real;
summ:real;
summd:real;
i,l,m:integer;
const n=10;
begin
for i:= 1 to n do
if Length(StringGrid1.Cells[i-1, 0]) <>0
then a[i]:= StrToFloat(StringGrid1.Cells[i-1,0])
else a[i]:= 0;
summ:=0;
for i:=1 to n do
if i mod 2<>0 then summ:= summ + a[i];
Label1.Caption:='Сумма1: ' + FloatToStr(summ);
l:=0;
m:=0;
for i:=1 to n do
if a[i]<0 then
begin
m:=i;
break;
end;
for i:=n downto m do
if a[i]<0 then
begin
l:=i;
break;
end;
summd:=0;
for i:=l+1 to m-1 do
summd:=summd + a[i];
Label2.Caption:='Сумма2: ' + FloatToStr(summd);
end;
end.
теперь вторая сумма выводит "0"