VB二维数组打印下三角和上三角
012234345645678012342345456678下面是右上直角三角形...
0
1 2
2 3 4
3 4 5 6
4 5 6 7 8
0 1 2 3 4
2 3 4 5
4 5 6
6 7
8
下面是右上直角三角形 展开
1 2
2 3 4
3 4 5 6
4 5 6 7 8
0 1 2 3 4
2 3 4 5
4 5 6
6 7
8
下面是右上直角三角形 展开
2个回答
展开全部
Private Sub Command1_Click()
Dim a&(4, 4), i&, j&
For i = 0 To 4
For j = 0 To 4
a(i, j) = i + j
Next
Next
'打印下三角
For i = 0 To 4
For j = 0 To i
Print " " & a(i, j);
Next
Print
Next
Print
'打印上三角
For i = 0 To 4
Print String(i * 2, " ");
For j = i To 4
Print " " & a(i, j);
Next
Print
Next
End Sub
Dim a&(4, 4), i&, j&
For i = 0 To 4
For j = 0 To 4
a(i, j) = i + j
Next
Next
'打印下三角
For i = 0 To 4
For j = 0 To i
Print " " & a(i, j);
Next
Next
'打印上三角
For i = 0 To 4
Print String(i * 2, " ");
For j = i To 4
Print " " & a(i, j);
Next
Next
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim mArrA(0 To 4, 1 To 5), mArrB(0 To 4, 1 To 5), i%, j%
For i = 0 To 4
For j = 1 To i + 1
If j = 1 Then
mArrA(i, j) = i
Else
mArrA(i, j) = mArrA(i, j - 1) + 1
End If
Print mArrA(i, j);
Next j
Print
Next i
Print
Print
For i = 0 To 4
For j = 1 To 5
If j = 1 Then
mArrB(i, j) = i
Else
mArrB(i, j) = mArrB(i, j - 1) + 1
End If
If j >= i + 1 Then
Print mArrB(i, j);
Else
Print Spc(3);
End If
Next j
Print
Next i
End Sub
Dim mArrA(0 To 4, 1 To 5), mArrB(0 To 4, 1 To 5), i%, j%
For i = 0 To 4
For j = 1 To i + 1
If j = 1 Then
mArrA(i, j) = i
Else
mArrA(i, j) = mArrA(i, j - 1) + 1
End If
Print mArrA(i, j);
Next j
Next i
For i = 0 To 4
For j = 1 To 5
If j = 1 Then
mArrB(i, j) = i
Else
mArrB(i, j) = mArrB(i, j - 1) + 1
End If
If j >= i + 1 Then
Print mArrB(i, j);
Else
Print Spc(3);
End If
Next j
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询