输出一个5×5的矩阵,其中元素是随机生成的1-100的整数.

1个回答

  • Private Sub Command1_Click()

    Randomize

    Form1.Cls

    Dim c,e As Integer

    c = 0

    e = 0

    Dim d As Double

    d = 1

    Dim a(4,4) As String

    For i = 0 To 4

    For j = 0 To 4

    f = Format(Int(Rnd * 100 + 1),"0,0")

    If i = j Or i + j = 4 Then c = c + f:d = d * f

    If f > e Then e = f

    a(i,j) = f

    Next

    Print a(i,0) & " " & a(i,1) & " " & a(i,2) & " " & a(i,3) & " " & a(i,4)

    Next

    Print "对角线的和为:" & c

    Print "对角线的积为:" & d

    Print "最大的元素为:" & e

    End Su