vb利用随机函数产生并显示0和1构成6*6的矩阵,在窗体显示下三角形并统计三角形中的
1个回答
展开全部
Private Sub Form_Load()
Randomize Timer
Me.AutoRedraw = True
Print "原始矩阵:"
Dim i As Integer, j As Integer
Dim a(5, 5) As Integer, sum As Integer
For i = 0 To 5
For j = 0 To 5
a(i, j) = IIf(Rnd >= 0.5, 1, 0)
Print a(i, j);
Next
Next
Print "下三角形:"
For i = 0 To 5
For j = 0 To i
Print a(i, j);
If a(i, j) = 1 Then sum = sum + 1
Next
Next
Print "1的个数是:"; sum
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |