用VB编写一个程序,计算出给定的10*10矩阵(存放在二维数组A中)每行元素的最大值和每列元素的最小值

1个回答

  • Module Module1

    Sub Main()

    Dim A(,) As Integer = {{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0}}

    Dim Rows(10) As Integer

    Dim Cols(10) As Integer

    Dim i,j As Integer

    Dim max,min As Integer

    For i = 0 To A.GetLength(0) - 1

    Rows(i) = A(i,0)

    For j = 0 To A.GetLength(1) - 1

    If (A(i,j) > Rows(i)) Then

    Rows(i) = A(i,j)

    End If

    Next

    Next

    For j = 0 To A.GetLength(1) - 1

    Cols(j) = A(j,0)

    For i = 0 To A.GetLength(0) - 1

    If (A(i,j) < Cols(j)) Then

    Cols(j) = A(i,j)

    End If

    Next

    Next

    min = Rows(0)

    For i = 1 To A.GetLength(0) - 1

    If Rows(i) < min Then

    min = Rows(i)

    End If

    Next

    max = Cols(0)

    For i = 1 To A.GetLength(1) - 1

    If Cols(i) > max Then

    max = Rows(i)

    End If

    Next

    If min > max Then

    Console.WriteLine("row")

    Else

    Console.WriteLine("col")

    End If

    End Sub

    End Module