VBA语言 用循环结构输出如下图形(菱形带数字)
2个回答
展开全部
Sub avav()
Dim a As Range, i%, j%, k%
Range("a1:a11").Clear
'
Range("A1:A11").NumberFormatLocal = "@"
Set a = Range("A1")
For i = -5 To 5
'a = a & "X"
For k = 1 To 2
'空格
For j = 1 To Abs(i)
a = a & " "
Next j
For j = 1 To 5 - Abs(i)
a = a & "*"
Next j
a = a & Abs(i)
For j = 1 To 5 - Abs(i)
a.Value = a.Value & "*"
Next j
For j = 1 To Abs(i)
a.Value = a.Value & " "
Next j
Next k
a = a & " "
Set a = a.Offset(1, 0)
Next i
End Sub
Dim a As Range, i%, j%, k%
Range("a1:a11").Clear
'
Range("A1:A11").NumberFormatLocal = "@"
Set a = Range("A1")
For i = -5 To 5
'a = a & "X"
For k = 1 To 2
'空格
For j = 1 To Abs(i)
a = a & " "
Next j
For j = 1 To 5 - Abs(i)
a = a & "*"
Next j
a = a & Abs(i)
For j = 1 To 5 - Abs(i)
a.Value = a.Value & "*"
Next j
For j = 1 To Abs(i)
a.Value = a.Value & " "
Next j
Next k
a = a & " "
Set a = a.Offset(1, 0)
Next i
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个就用for循环控制啊
更多追问追答
追问
不太懂,能具体点吗?数字的部分要怎么处理呢?
追答
好吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询