⑴ 用VB的循环结构编写数字金字塔
Private Sub Command1_Click()
For i = 1 To 9
Print Spc(9 - i);
For j = 1 To i
Print Chr(48 + j);
Next j
For j = i - 1 To 1 Step -1
Print Chr(48 + j);
Next j
Next i
End Sub
⑵ 求VB代码_数字金字塔
PrivateSubCommand1_Click()
DimiAsInteger,jAsInteger
PrintSpace(27);1
Fori=2To9
PrintSpace(30-3*i);
Forj=1Toi
Printj;
Nextj
Forj=i-1To1Step-1
Printj;
Nextj
Nexti
EndSub
左边没对齐,好用啊
⑶ vb输出数字金字塔
示例代码如下:
PrivateSubCommand1_Click()
DimiAsInteger
DimjAsInteger
DimsAsString
Fori=1To5Step1
s=String(i*2-1,CStr(i))
PrintSpc((10-i*2)/2);s
Nexti
Forj=6To9Step1
s=String(9-2*(j-5),CStr(j))
PrintSpc(j-5);s
Nextj
EndSub
⑷ VB中怎么编数字金字塔
Private Sub Form_Click()
Dim i As Integer, j As Integer
For i = 1 To 9
If i <= 5 Then
Print Space(5 - i);
For j = 1 To (i - 1) * 2 + 1
If j = (i - 1) * 2 + 1 Then
Print CStr(i)
Else
Print CStr(i);
End If
Next j
Else
Print Space(i - 5);
For j = 1 To (10 - i - 1) * 2 + 1
If j = (10 - i - 1) * 2 + 1 Then
Print CStr(i)
Else
Print CStr(i);
End If
Next j
End If
Next i
'点击窗口任意位置即可
End Sub
⑸ VB代码,数字金字塔
不好意思,刚上,才看见你给我发的信息。
你肯定把题目图案弄错了,第二行三个2吧……
我就上楼上的基础上加了一个j
Private Sub Command1_Click()
Dim i, j As Integer
Dim s As String
j = -1
For i = 1 To 10
j = j + 2
s = String(j, Right(Trim(Str(i)), 1))
Print Tab(11 - i); s
Next i
End Sub
⑹ 用VB编程如何打印数字金字塔
For i = 1 To 9 For j = 1 To 9 - i Print " "; Next j For j = 1 To i Print j; Next j For j = i - 1 To 1 Step -1 Print j; Next j Print Next i
⑺ vb编程数字金字塔
试编写代码示例如下:
PrivateSubCommand1_Click()
Fori=1To9
s=""
Forj=1Toi
s=s&""&(i-1)*2+1
Nextj
Prints
Nexti
EndSub
运行截图: