информатикаzadacha_5
.docxСоставьте процедуру, определяющую среднее арифметическое значение элементов одномерного массива. Если среднее арифметическое значение элементов одномерного массива А отличается от среднего арифметического значения элементов массива В менее чем на заданную величину ? , то выведите сообщение "А и В равнозначны". В противном случае выведите среднее арифметическое значение, полученное для каждого массива.
5.Public Class Form1
Private Sub btnПуск_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnПуск.Click
Dim n, u, h As Integer
Dim SumA, Sumb As Single
Dim a() As Single, b() As Single
txtЖурнал.Clear()
n = InputBox _
("Задайте количество ячеек векторов а и б")
txtЖурнал.AppendText("n = " & n & vbCrLf)
u = InputBox _
("Задайте порог")
txtЖурнал.AppendText("u= " & u & vbCrLf)
ReDim a(n), b(n)
InputVector(a, "a")
txtЖурнал.AppendText("Матрица a" & vbCrLf)
OutputVector(a, txtЖурнал)
InputVector(b, "b")
txtЖурнал.AppendText("Матрица b" & vbCrLf)
OutputVector(b, txtЖурнал)
Упр(a, SumA)
Упр(b, Sumb)
h = SumA - Sumb
If h <= u Then
txtЖурнал.AppendText("А и В равнозначны" & vbCrLf)
Else
txtЖурнал.AppendText("Средне арифм А " & SumA & vbCrLf)
txtЖурнал.AppendText("Средне арифм В " & Sumb & vbCrLf)
End If
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Label1.Click
End
End Sub
Private Sub Упр(ByVal x() As Single, ByRef Сумма As Single)
Dim i, Sum, kol As Integer
For i = 1 To x.GetUpperBound(0)
Sum = Sum + x(i)
kol = kol + 1
Next
Сумма = Sum / kol
End Sub
Private Sub InputMatrix(ByRef x(,) As Single, Optional _
ByVal ArrayName As String = "элемент")
Dim i, j As Integer
For i = 1 To x.GetUpperBound(0)
For j = 1 To x.GetUpperBound(1)
x(i, j) = InputBox(ArrayName & _
"(" & i & "," & j _
& ") = ?")
Next
Next
End Sub
Private Sub OutputMatrix(ByVal x(,) As Single, _
ByVal y As TextBox)
Dim i, j As Integer
For i = 1 To x.GetUpperBound(0)
For j = 1 To x.GetUpperBound(1)
y.AppendText(x(i, j) & vbTab)
Next
y.AppendText(vbCrLf)
Next
End Sub
Private Sub InputVector(ByRef x() As Single, Optional _
ByVal ArrayName As String = "элемент")
Dim i As Integer
For i = 1 To x.GetUpperBound(0)
x(i) = InputBox(ArrayName & "(" & i & ") = ?")
Next
End Sub
Private Sub OutputVector(ByVal x() As Single, _
ByVal y As TextBox)
Dim i As Integer
For i = 1 To x.GetUpperBound(0)
y.AppendText(x(i) & vbTab)
Next
y.AppendText(vbCrLf)
End Sub
End Class