Private Sub Form_Click()
Dim SymbolCount As Integer '输出符号的最大个数,即最底层字母或符号的个数
Dim SpaceCount As Integer '左边的空格数
Dim OutPutSpace As String '保存要输出的左边的空格
Dim OutPutSymbol As String '保存要输出的字符和字符间的空格
Dim i, j As Integer
SymbolCount = 5 '设定金字塔的高度为5层,最底层输出的符号也刚好是5个
SpaceCount = (SymbolCount * 2 - 1) 消举逗/ 2 '左边空格数的初始值等于底层输出字符+字符间空格的个数的一半
OutPutSymbol = "*"
OutPutSpace = ""
For i = 1 答腊To SpaceCount '计算第一行左边所需要输出的空格数目
OutPutSpace = OutPutSpace & " " '累加空格数目
Next i
For i = 1 To SymbolCount
Print OutPutSpace & OutPutSymbol '输出计算后得出的这行的结果
If SpaceCount > 0 Then
SpaceCount = SpaceCount - 1
End If
OutPutSpace = Left(OutPutSpace, SpaceCount) '左边空格,下一行比上一行少一个空格
拿卖OutPutSymbol = OutPutSymbol & " *" '下一行比上一行多一个空格和一个星号
Next i
End Sub
Private Sub Form_click()'点击窗体就可以纤吵 Dim i As Long, m As Long, z As Long
For i = 1 To 24
念嫌 m = i * 2
z = z + 仔竖手m
Next
Print "共有宝物" & z
End Sub
结果是:600
分类: 电脑/网络 >>程序设计 >>其他编程语言问题描述:
求帮忙啦
解析:
程序如下,在窗体的单击事件下实现:
Private Sub Form_Click()
\'杨辉三角图形
\'梁拍
\' 1
\' 1 1
\' 1 2 1
\' 1 3 3 1
\' 1 4 6 4 1
\'
\'下面的行值为上面行中相邻数之和
Dim i As Integer \'外循环变量
Dim j As Integer \'内循环变量
Dim a(1 To 5, 1 To 5) As Integer \'数组声明
For i = 1 To 5 \'左边和右边两侧赋值1
a(i, 1) = 1
a(i, i) = 1
Next
For i = 3 To 5
For j = 2 To i \'滚搏中间部分的元素赋值,从图中可看出规律
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next
Next
For i = 1 To 5
Print Tab(19 - 2 * i)\'缩进
For j = 1 To i
Print a(i, j)\" \"\'打印大渣祥
Next
Print \'换行
Next
End Sub
程序在WinXP+VB6.0环境下运行成功! "\"表示是空格
有问题来群:***********讨论!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)