uses Crt; const N=30; type Mas=array [1..N] of integer; var i, j , SumPol, SumOtr: integer; A: Mas; begin ClrScr; SumPol:=0; SumOtr:=0; WriteLn(' Sposob 1:'); WriteLn; for i:=1 to N do begin A[i]:=-10+random(21); Write (A[i]:4); end; WriteLn; for i:=1 to N do begin if (A[i]>0) then SumPol:=SumPol+A[i]; if (A[i]<0) then SumOtr:=SumOtr+A[i]; end; WriteLn(' SumPol =', SumPol); WriteLn(' SumOtr =', SumOtr); WriteLn; WriteLn (' Sposob 2:') ; SumPol:=0; SumOtr:=0; i:=1; repeat if (A[i]>0) then SumPol:=SumPol+A[i]; if (A[i]<0) then SumOtr:=SumOtr+A[i]; i:=i+1; until i>30; WriteLn(' SumPol =', SumPol); WriteLn(' SumOtr =', SumOtr); ReadLn; end.
А получилось вот что:
uses Crt;
const N=30;
type Mas=array [1..N] of integer;
var i, j , SumPol, SumOtr: integer;
A: Mas;
begin
ClrScr;
SumPol:=0;
SumOtr:=0;
WriteLn(' Sposob 1:');
WriteLn;
for i:=1 to N do
begin
A[i]:=-10+random(21);
Write (A[i]:4);
end;
WriteLn;
for i:=1 to N do
begin
if (A[i]>0) then SumPol:=SumPol+A[i];
if (A[i]<0) then SumOtr:=SumOtr+A[i];
end;
WriteLn(' SumPol =', SumPol);
WriteLn(' SumOtr =', SumOtr);
WriteLn;
WriteLn (' Sposob 2:') ;
SumPol:=0;
SumOtr:=0;
i:=1;
repeat
if (A[i]>0) then SumPol:=SumPol+A[i];
if (A[i]<0) then SumOtr:=SumOtr+A[i];
i:=i+1;
until i>30;
WriteLn(' SumPol =', SumPol);
WriteLn(' SumOtr =', SumOtr);
ReadLn;
end.