我的程序是:
Private Sub Command1_Click()
Cls
Dim a() As Integer, RowMax%, ColMin%, i%, j%, M%, N%
Dim Point As Integer, Col% '鞍点
Dim flag As Integer
Randomize
M = Int(Rnd * 8) + 1
N = Int(Rnd * 8) + 1
ReDim a(M, N) As Integer '重新定义改变维数和大小
'生成数组
Print Chr(13) + Chr(13); "随机生成的数组为:"; Chr(13)
For i = 0 To M '行
For j = 0 To N '列
a(i, j) = Int(Rnd * 90) + 10 '产生随机两位整数
Print a(i, j); " ";
Next j
Print
Next i
Print
'统计数组元素
For i = 0 To M
RowMax = a(i, 0) '假设每行第一列的元素为行最大
For j = 0 To N
If a(i, j) > RowMax Then RowMax = a(i, j)
Next j
Print "第" & i + 1 & "行最大的元素是:"; RowMax
Next i
Print
For j = 0 To N
ColMin = a(0, j) '假设每列第一行的元素为列最小
For i = 0 To M
If a(i, j) < ColMin Then ColMin = a(i, j)
Next i
Print "第" & j + 1 & "列最小的元素为:"; ColMin
Next j
Print
'查找鞍点
For i = 0 To M
Point = a(i, 0): Col = 0
For j = 0 To N
If Point < a(i, j) Then Point = a(i, j): Col = j
Next j
flag = 1
For j = 0 To N
If Point > a(j, Col) Then flag = 0
Next j
If flag Then
Print "第" & i + 1 & "行鞍点元素是:"; Point
Else
Print "第" & i + 1 & "行鞍点元素不存在!"
End If
Next i
End Sub
但是运行时有时候正确,有时候却有“下标越界”的错误:If Point > a(j, Col) Then!! 实在迷惑,请大家帮忙修改!
在一个数组中查找鞍点