- •VbCrLf)
- •Imports System.Math
- •Imports System.Math
- •InputVector(a, "a")
- •InputVector(b, "b")
- •Imports System.Math
- •InputVector(a, "a")
- •InputVector(b, "b")
- •InputVector(a, "a")
- •InputVector(b, "b")
- •VbCrLf)
- •VbCrLf)
- •VbCrLf)
- •InputVector(a, "a")
- •InputVector(b, "b")
- •InputVector(a, "a")
- •InputVector(b, "b")
- •InputVector(a, "a")
- •InputVector(b, "b")
InputVector(a, "a")
txtЖурнал.AppendText("Матрица a" & vbCrLf)
OutputVector(a, txtЖурнал)
InputVector(b, "b")
txtЖурнал.AppendText("Матрица b" & vbCrLf)
OutputVector(b, txtЖурнал)
Упр(a, h)
Упр(b, h)
If Упр(a, h) Then
txtЖурнал.AppendText("Массив A" & vbCrLf)
OutputVector(a, txtЖурнал)
ElseIf Упр(b, h) Then
txtЖурнал.AppendText("Массив B" & vbCrLf)
OutputVector(b, txtЖурнал)
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 Function Упр(ByVal x() As Single, ByVal Порог As Single) As Boolean
Dim i As Integer
Упр = True
For i = 1 To x.GetUpperBound(0)
If x(i) <= Порог Then
Упр = False
End If
Next
End Function
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
Составьте функцию, вычисляющую количество элементов одномерного массива, значение которых больше заданной величины h1, но в тоже время меньше заданной величины h2. Используйте эту функцию для одномерных массивов А и В и выведите имя массива, у которого количество таких элементов окажется больше.
4.Public Class Form1
Private Sub btnПуск_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnПуск.Click
Dim n, h1, h2 As Integer
Dim a() As Single, b() As Single
txtЖурнал.Clear()
n = InputBox _
("Задайте количество ячеек векторов а и б")
txtЖурнал.AppendText("n = " & n & vbCrLf)
h1 = InputBox _
("Задайте порог")
txtЖурнал.AppendText("h1= " & h1 & vbCrLf)
h2 = InputBox _
("Задайте порог")
txtЖурнал.AppendText("h2= " & h2 & 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, h1, h2)
Упр(b, h1, h2)
If Упр(a, h1, h2) > Упр(b, h1, h2) Then
txtЖурнал.AppendText("Массив A" & vbCrLf)
End If
If Упр(a, h1, h2) < Упр(b, h1, h2) Then
txtЖурнал.AppendText("Массив B" & 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 Function Упр(ByVal x() As Single, ByVal Порог1 As Integer, ByVal Порог2 As Integer) As Boolean
Dim i As Integer
Упр = 0
For i = 1 To x.GetUpperBound(0)
If x(1) > Порог1 And x(i) < Порог2 Then
Упр = Упр + 1
End If
Next
End Function
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
Составьте процедуру, определяющую среднее арифметическое значение элементов одномерного массива. Если среднее арифметическое значение элементов одномерного массива А отличается от среднего арифметического значения элементов массива В менее чем на заданную величину ? , то выведите сообщение "А и В равнозначны". В противном случае выведите среднее арифметическое значение, полученное для каждого массива.
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)