用VB编出程序 1 121 12321 1234321 利用FOR语句和IF语句和数列编

形状是塔式的。。 1 121 123211234321
2024-11-29 02:10:31
推荐回答(2个)
回答1:

Private Sub Command1_Click()
Dim i, a As Integer, b As String
Do
a = Val(InputBox("输入层数:"))
Loop While a < 2 Or a > 9
For i = 1 To a
b = ""
For j = 1 To (i - 1) * 2 + 1
b = b & IIf(j > i, CStr(i * 2 - j), CStr(j))
Next
Print Space(a + 1 - i) & b
Next
End Sub

回答2:

Private Sub Command1_Click()
Dim n As Integer

n = Val(InputBox("输入层数:"))

For i = 1 To n
Print Spc(n - i);
For j = -i To i
If i - Abs(j) > 0 Then Print Trim(i - Abs(j));
Next j
Print
Next i
End Sub