VB实验报告“找出二维数组n×m中的鞍点”
姓名:叶大塽
班级及学号:电气2班15050342035
日期:2016年5月26日
一.实验目的
设计Vb程序,找出二维数组n×m中的鞍点。
二.实验内容
找出二维数组n×m中的鞍点,所谓的鞍点是指它在本行中值最大,在本列中值最小,输出鞍点的行,列,有可能在一个数组中找不到一个鞍点,如无鞍点则输出“无”。
三.实验程序
Private Sub Command1_Click()
Dim i As Integer, j As Integer, c As Integer, r As Integer
Dim n As Integer
cs1
xs
For i = 1 To 4
For j = 1 To 4 Private Sub Command1_Click()
Dim i As Integer, j As Integer, c As Integer, r As Integer
Dim n As Integer
cs1
xs
For i = 1 To 4
For j = 1 To 4
If a(i, 0) < a(i, j) Then
c = j
a(i, 0) = a(i, j)
End If
Next
n = 0
For j = 1 To 4
If a(i, 0) < a(j, c) Then
Print "+";
n = n + 1
End If
Next
If n = 3 Then Print "a(" & i & "," & c & ")"; a(i, c)
Next
xs
End Sub
Public a(4, 4) As Integer
Public Sub xs()
Dim i As Integer, j As Integer
For i = 1 To 4
For j = 0 To 4
Form1.Print a(i, j); " ";
Next
Form1.Print
Next
End Sub
Public Sub cs0()
a(1, 1) = 1
a(1, 2) = 1
a(1, 3) = 1
a(1, 4) = 1
a(2, 1) = 1
a(2, 2) = 1
a(2, 3) = 1
a(2, 4) = 1
a(3, 1) = 1
a(3, 2) = 1
a(3, 3) = 1
a(3, 4) = 1
a(4, 1) = 1
a(4, 2) = 1
a(4, 3) = 1
a(4, 4) = 1
End Sub
Public Sub cs1()
a(1, 1) = 1
a(1, 2) = 2
a(1, 3) = 3
a(1, 4) = 4
a(2, 1) = 1
a(2, 2) = 1
a(2, 3) = 1
a(2, 4) = 5
a(3, 1) = 1
a(3, 2) = 1
a(3, 3) = 1
a(3, 4) = 6
a(4, 1) = 1
a(4, 2) = 1
a(4, 3) = 1
a(4, 4) = 7
End Sub
Public Sub cs2()
a(1, 1) = 1
a(1, 2) = 1
a(1, 3) = 5
a(1, 4) = 1
a(2, 1) = 1
a(2, 2) = 2
a(2, 3) = 4
a(2, 4) = 3
a(3, 1) = 1
a(3, 2) = 1
a(3, 3) = 6
a(3, 4) = 1
a(4, 1) = 1
a(4, 2) = 1
a(4, 3) = 7
a(4, 4) = 1
End Sub
Public Sub cs3()
a(1, 1) = 1
a(1, 2) = 5
a(1, 3) = 1
a(1, 4) = 1
a(2, 1) = 1
a(2, 2) = 4
a(2, 3) = 2
a(2, 4) = 3
a(3, 1) = 1
a(3, 2) = 6
a(3, 3) = 1
a(3, 4) = 1
a(4, 1) = 1
a(4, 2) = 7
a(4, 3) = 1
a(4, 4) = 1
End Sub
If a(i, 0) < a(i, j) Then
c = j
a(i, 0) = a(i, j)
End If
Next
n = 0
For j = 1 To 4
If a(i, 0) < a(j, c) Then
Print "+";
n = n + 1
End If
Next
If n = 3 Then Print "a(" & i & "," & c & ")"; a(i, c)
Next
xs
End Sub
Public a(4, 4) As Integer
Public Sub xs()
Dim i As Integer, j As Integer
For i = 1 To 4
For j = 0 To 4
Form1.Print a(i, j); " ";
Next
Form1.Print
Next
End Sub
Public Sub cs0()
a(1, 1) = 1
a(1, 2) = 1
a(1, 3) = 1
a(1, 4) = 1
a(2, 1) = 1
a(2, 2) = 1
a(2, 3) = 1
a(2, 4) = 1
a(3, 1) = 1
a(3, 2) = 1
a(3, 3) = 1
a(3, 4) = 1
a(4, 1) = 1
a(4, 2) = 1
a(4, 3) = 1
a(4, 4) = 1
End Sub
Public Sub cs1()
a(1, 1) = 1
a(1, 2) = 2
a(1, 3) = 3
a(1, 4) = 4
a(2, 1) = 1
a(2, 2) = 1
a(2, 3) = 1
a(2, 4) = 5
a(3, 1) = 1
a(3, 2) = 1
a(3, 3) = 1
a(3, 4) = 6
a(4, 1) = 1
a(4, 2) = 1
a(4, 3) = 1
a(4, 4) = 7
End Sub
Public Sub cs2()
a(1, 1) = 1
a(1, 2) = 1
a(1, 3) = 5
a(1, 4) = 1
a(2, 1) = 1
a(2, 2) = 2
a(2, 3) = 4
a(2, 4) = 3
a(3, 1) = 1
a(3, 2) = 1
a(3, 3) = 6
a(3, 4) = 1
a(4, 1) = 1
a(4, 2) = 1
a(4, 3) = 7
a(4, 4) = 1
End Sub
Public Sub cs3()
a(1, 1) = 1
a(1, 2) = 5
a(1, 3) = 1
a(1, 4) = 1
a(2, 1) = 1
a(2, 2) = 4
a(2, 3) = 2
a(2, 4) = 3
a(3, 1) = 1
a(3, 2) = 6
a(3, 3) = 1
a(3, 4) = 1
a(4, 1) = 1
a(4, 2) = 7
a(4, 3) = 1
a(4, 4) = 1
End Sub
四.实验问题及解决方法
对程序无从下手,还的继续学习。Vb的确是很实用的软件,学好前途无量。但是也确实难学,学了这么久了,我还没有看出其中的要点,还不能真正入门,感觉太难。以后再接再厉吧