| в общем вот решение но я не уверен правильно ли
Public Sub DynArray()
Dim N As Byte, x As Byte, y As Byte, SumA As Double, SumB As Double, CountA As Integer, CountB As Integer
Dim MinusA As Double, MinusB As Double, CountArray As Integer
Dim a() As Integer
Dim b() As Integer
Dim CA() As Double
Dim CB() As Double
Dim oustr As String
MinusA = 0: MinusB = 0: x = 0: y = 0: z = 0: N = 0
N = InputBox("Введите число элементов массива (не менее 3-х !!!)")
ReDim a(N, N)
ReDim b(N, N)
ReDim CA(N)
ReDim CB(N)
For x = 1 To N
For y = 1 To N
a(x, y) = Int((Rnd * 1000) - (Rnd * 1000))
b(x, y) = Int((Rnd * 1000) - (Rnd * 1000))
If a(x, y) >= 0 Then
SumA = SumA + a(x, y): CountA = CountA + 1
End If
If b(x, y) >= 0 Then
SumB = SumB + b(x, y): CountB = CountB + 1
End If
If x = y And a(x, y) < 0 And MinusA <> 0 Then
MinusA = MinusA * a(x, y)
Else
MinusA = a(x, y)
End If
If x = y And b(x, y) < 0 And MinusB <> 0 Then
MinusB = MinusB * b(x, y)
Else
MinusB = b(x, y)
End If
If x = y Then
CA(x) = a(x, y)
CB(x) = b(x, y)
End If
Next
Next
y = 0: x = 0: z = 0
oustr = ""
If MinusA = MinusB Then
MsgBox "Значение главных диагоналей равно"
Exit Sub
End If
If MinusA >= 0 And MinusB >= 0 Then
MsgBox "Не найдено отрицательных элементов"
Exit Sub
End If
If MinusA < MinusB Then
z = SumA / CountA
For x = 1 To N
CA(x) = CA(x) / z
oustr = oustr + Str(CA(x)) + "|"
Next x
MsgBox oustr, , "Значение массива С (использован массив А)"
End If
y = 0: x = 0: z = 0
oustr = ""
If MinusA > MinusB Then
z = SumB / CountB
For y = 1 To N
CB(y) = CB(y) / z
oustr = oustr + Str(CB(y)) + "|"
Next
MsgBox oustr, , "Значение массива С (использован массив В)"
End If
End Sub | |