五笔打字通主页
VB程序题:参照教材例5.3,在通用声明段声明两个数组,利用随机函数形成如下两个数组: 龚沛曾
要求:
1.以下三角形式迷魂汤A数组,上三角形式显示B数组。
2.求A数组主对角线元素之和和B数组副对角线元素之和。
解题,在窗体上画三个按钮,三个图片框,代码如下:
Dim a%(3, 3), b%(3, 3)
Private Sub Form_Load()
For i = 0 To 3
For j = 0 To 3
a(i, j) = Int(Rnd * 36 + 35)
b(i, j) = Int(Rnd * 41 + 100)
Next j
Next i
End Sub
Private Sub Command1_Click()
Picture1.Cls
For i = 0 To 3
For j = 0 To i
Picture1.Print a(i, j); " ";
Next j
Picture1.Print
Next i
End Sub
Private Sub Command2_Click()
Picture2.Cls
For i = 0 To 3
For j = i To 3
Picture2.Print Tab(j * 6); b(i, j);
Next j
Picture2.Print
Next i
End Sub
Private Sub Command3_Click()
Picture3.Cls
sa = 0
For i = 0 To 3
sa = sa + a(i, i)
Next i
sb = 0
For i = 0 To 3
sb = sb + b(i, 3 - i)
Next i
Picture3.Print "A数组主对角线元素和为:"; sa
Picture3.Print "B数组副对角线元素和为:"; sb
End Sub
运行程序效果图如下:
Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码
来源:济亨网
本文链接:http://wb86.com/post/83.html