VB源程序如下:
Option Base 1
Private Sub Command1_Click()
Dim A(5, 5) As Integer, B(5, 5) As Integer
For x = 1 To 5
For y = 1 To 5
A(x, y) = Int(10 + Rnd * 90) '随机产生两位数的整数
Print A(x, y) '输出
Next
Next
For x = 1 To 5
For y = 1 To 5
B(x, y) = A(y, x) '转置
Print B(x, y) '输出
Next
Next
End Sub
程序输出结果如下:
扩展资料:
VB:编写程序,实现如下规律的5*5矩阵存入数组,并输出该数组
Private Sub Command1_Click()
Dim a(1 To 6, 1 To 6) As Integer
For i = 1 To 5
For j = 1 To 5
tmp = 99
If i <tmp Then
tmp = i
End If
If j <tmp Then
tmp = j
End If
If 6 - i <tmp Then
tmp = 6 - i
End If
If 6 - j <tmp Then
tmp = 6 - j
End If
a(i, j) = tmp
Next j
Next i
For i = 1 To 5
For j = 1 To 5
Picture1.Print Tab(j * 5)a(i, j)
Next j
Picture1.Print
Next i
End Sub
程序输出结果如下:
修改后,,,你第二次点commad(index)时,吧数组里的值又清掉了Option Base 1
Private a%(), b%(), c$()
Private Sub Command1_Click(Index As Integer)
Dim n%, i%, q$, w$, e$
If Index = 0 Then
n = Val(Text1(0))
ReDim a%(n), b%(n), c$(n)
Randomize
For i = 1 To n
a(i) = Int((Rnd * 99) + 1)
q = a(i) &IIf(a(i) <10, Space(3), Space(2)) &q
b(i) = Int((Rnd * 99) + 1)
w = b(i) &IIf(b(i) <10, Space(3), Space(2)) &w
e = a(i) + b(i) &IIf(a(i) + b(i) <100, Space(2), Space(1)) &e
Next
Text1(1) = q: Text1(2) = w
Else
For i = 1 To n - 1
e = a(i) + b(i) &IIf(a(i) + b(i) <100, Space(2), Space(1)) &e
Text1(3) = e
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)