Sub aaa() Dim i As Integer, j As Integer, d ReDim q(1 To 3, 1 To 2) For i = 1 To 3 For j = 1 To 2 q(i, j) = InputBox("Введите элемент (" + Str(i) + "," + Str(j) + ")") Next j Next i Cells(1, 1).Value = "Исходный массив" Range(Cells(2, 1), Cells(4, 2)).Value = q Cells(5, 1).Value = "Результирующий массив" For i = 1 To 3 If q(i, 1) > q(i, 2) Then d = q(i, 1): q(i, 1) = q(i, 2): q(i, 2) = d End If Next i Range(Cells(6, 1), Cells(8, 2)).Value = q End Sub
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.
Dim i As Integer, j As Integer, d
ReDim q(1 To 3, 1 To 2)
For i = 1 To 3
For j = 1 To 2
q(i, j) = InputBox("Введите элемент (" + Str(i) + "," + Str(j) + ")")
Next j
Next i
Cells(1, 1).Value = "Исходный массив"
Range(Cells(2, 1), Cells(4, 2)).Value = q
Cells(5, 1).Value = "Результирующий массив"
For i = 1 To 3
If q(i, 1) > q(i, 2) Then
d = q(i, 1): q(i, 1) = q(i, 2): q(i, 2) = d
End If
Next i
Range(Cells(6, 1), Cells(8, 2)).Value = q
End Sub
А получилось вот что:
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.