21
: ,
: 1. - .
2. , .
3. .
:
- .
- ?
- ?
- .
- .
:
- ;
- , ;
- .
. :
- , .
- . , .
- - . .
- . . , .
- , , . .
, .. , , .. .
( ) - , , . . , .
, .
: . , . .
Public Class Form1
Dim m1(,), m2(,) As Integer
Dim n1, n2 As Integer
Private Sub inicial(ByVal m(,) As Integer, ByVal n As Integer, ByVal lab As Object)
'
Dim i, j As Integer
lab.text = ""
For i = 1 To n
For j = 1 To n
|
|
m(i, j) = Int(Rnd() * 20 - i - Rnd(10) * j * 0.56)
lab.Text = lab.Text + Format(m(i, j), "0 ")
Next
lab.Text = lab.Text + vbCrLf
Next
End Sub
Private Sub sredn_pol(ByVal m(,) As Integer, ByVal n As Integer, ByVal lab As Object)
'
Dim i, j, sum, k As Integer
Dim sr As Double
For i = 1 To n
For j = 1 To n
If m(i, j) > 0 Then
sum = sum + m(i, j)
k = k + 1
End If
Next
Next
sr = sum / k
lab.text = Format(sr, " 0.00 ")
End Sub
Private Sub sredn_otr(ByVal m(,) As Integer, ByVal n As Integer, ByVal lab As Object)
'
Dim i, j, sum, k As Integer
Dim sr As Double
For i = 1 To n
For j = 1 To n
If m(i, j) < 0 Then
sum = sum + m(i, j)
k = k + 1
End If
Next
Next
sr = sum / k
lab.text = Format(sr, " 0.00 ")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' 1
n1 = Int(InputBox(" ", " ", "5"))
ReDim m1(0 To n1, 0 To n1)
inicial(m1, n1, Label1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' 2
n2 = Int(InputBox(" ", " ", "4"))
ReDim m2(0 To n2, 0 To n2)
inicial(m2, n2, Label2)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' . 1
sredn_pol(m1, n1, Label3)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' . 2
sredn_pol(m2, n2, Label4)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
' . 1
sredn_otr(m1, n1, Label5)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
' . 2
sredn_otr(m2, n2, Label6)
End Sub
End Class
:
- ?
- ?
- -?
- - ?