Создать процедуру на языке vba дана последовательность целых чисел a1,…a45. получить число отрицательных элементов последовательности a1,…a35 и число нулевых элементов всей последовательности.
Требуемая процедура 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
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