二维数组m*n的鞍点
一:实验目的
设计vb程序,找到二维数组m*n中的鞍点。
二:实验内容
1.打开vb。
2.单击工具栏中的commandbutton,在form1上单击左键出现commandbutton。
3.单击commandbutton开始编写代码。
程序代码
注:括号内为解释说明。
Option Base 1
('m*n的二维数组,m行,n列)
Dim anma() As Integer
Dim m As Byte, n As Byte
Private Sub Command1_Click()
Cls
Me.Font.Size = 8
('生成二维数组)
('Dim m AsByte,n As Byte)
m= 5: n = 6
ReDim anma(m, n)
('此时数组里全是“0”)
('我们用一个双重循环来赋初值)
('i--m,j—n)
Dim i As Byte, j As Byte
For i = 1 To m
For j = 1 To n
anma(i, j) = 10 + Int(Rnd * 90)
('print(anma(i,j);Spc(3))
Next j
('print)
Next i
( '在窗体上输出已存在的二维数组)
('Dim i As Byte,j As Byte)
For i = 1 To m
For j = 1 To n
('anma(i,j)=10+nt(rnd*90))
Print anma(i, j); Spc(3)
Next j
Next i
'k------?
('对数组进行分析)
('row-max表示当前行上的最大值)
('column-max表示所找到的最大值所在的列号)
Dim row_max As Integer, column_max As Byte
For i = 1 To m
row_max = anma(i, 1)
column_max = 1
For j = 2 To n
If anma(i, j) > row_max Then
row_max = anma(i, j)
column_max = j
End If
Next j
For k = 1 To m
If anma(k, column_max) < row_max Then
Exit For
End If
Next k
If k = m + 1 Then
Print "鞍点:" & i & "," & column_max
End If
Next i
End Sub
4.编写完代码后点击运行即可出现数组。
三、实验心得
如果k<m则找不到鞍点,但K>m+1找得到鞍点