Требуемая процедура Sub ex1(ByRef a() As Integer, ByRef nn As Integer, ByRef nz As Integer) Dim i As Integer nn = 0: nz = 0 For i = 1 To 45 If a(i) = 0 Then nz = nz + 1 Else If a(i) < 0 And i <= 35 Then nn = nn + 1 End If End If Next i End Sub
Процедура для тестирования с выводом на лист Excel Sub Test() Dim p(1 To 45) As Integer Dim n1 As Integer, n2 As Integer, i As Integer Randomize Timer For i = 1 To 45 p(i) = Int(25 * Rnd - 12) Cells(i, 1) = p(i) Next i ex1 p, n1, n2 Cells(1, 2) = n1 Cells(1, 3) = n2 End Sub
Var ar:array[1..s] of integer; n,m,i:integer; begin writeln('N'); readln(n); writeln('M'); readln(m); writeln('Array:'); for i:=1 to s do readln(ar[i]); writeln('First array:'); for i:=1 to s do begin write(ar[i]:4); if ar[i] div n<>0 then ar[i]:=ar[i]+m; end; writeln; writeln('Final array:'); for i:=1 to s do write(ar[i]:4); end.
Пример ввода: 3 3 1 2 3 4 5 Пример вывода: First array: 1 2 3 4 5 Final array: 1 2 6 7 8
Sub ex1(ByRef a() As Integer, ByRef nn As Integer, ByRef nz As Integer)
Dim i As Integer
nn = 0: nz = 0
For i = 1 To 45
If a(i) = 0 Then
nz = nz + 1
Else
If a(i) < 0 And i <= 35 Then
nn = nn + 1
End If
End If
Next i
End Sub
Процедура для тестирования с выводом на лист Excel
Sub Test()
Dim p(1 To 45) As Integer
Dim n1 As Integer, n2 As Integer, i As Integer
Randomize Timer
For i = 1 To 45
p(i) = Int(25 * Rnd - 12)
Cells(i, 1) = p(i)
Next i
ex1 p, n1, n2
Cells(1, 2) = n1
Cells(1, 3) = n2
End Sub
Const
s=5;
Var
ar:array[1..s] of integer;
n,m,i:integer;
begin
writeln('N');
readln(n);
writeln('M');
readln(m);
writeln('Array:');
for i:=1 to s do
readln(ar[i]);
writeln('First array:');
for i:=1 to s do
begin
write(ar[i]:4);
if ar[i] div n<>0 then ar[i]:=ar[i]+m;
end;
writeln;
writeln('Final array:');
for i:=1 to s do
write(ar[i]:4);
end.
Пример ввода:
3
3
1
2
3
4
5
Пример вывода:
First array:
1 2 3 4 5
Final array:
1 2 6 7 8
//Блок-схема во вложении