[已解决]求个金字塔数字循环代码
本帖最后由 king8462 于 2017-7-22 14:40 编辑假设6行,如下图,搞了半天不会写了,求高手帮忙,谢谢!
for $i=1 to 6
for $k=1 to 21
MsgBox(0,"",$i&@CRLF&$k&@CRLF)
next
next
Local $sOut = '', $stmp = 0, $ii, $jj
For $ii = 1 To 6
For $jj = 1 To $ii
$stmp += 1
$sOut &= $stmp & @TAB
Next
$sOut &= @CRLF
Next
MsgBox(0, '', $sOut)
afan 发表于 2017-7-21 19:53 http://www.autoitx.com/images/common/back.gif
厉害了 本帖最后由 king8462 于 2017-7-21 22:54 编辑
回复 2# afan
多谢A版! 想了半天,还是想不出金字塔的该怎么写。。。。。a版那种的倒是简单 这个用C写最方便了
这里用StringFormat代替
Local $iLine = 10, $sOut = '', $iNum = 0
For $ii = 1 To $iLine
For $jj = $ii To $iLine - 1
$sOut &= " "
Next
For $jj = 1 To $ii
$iNum += 1
$sOut &= StringFormat("%-4d", $iNum)
Next
$sOut &= @CRLF
Next
MsgBox(0, '', $sOut)
回复 6# 帆船
For $jj = $ii To $iLine - 1
$sOut &= " "
Next
咳。。看了才发现原来好简单,,,脑残了俺。。太久没用了。。 再优化一下,另外用ConsoleWrite输出更整齐
Local $iLine = 20, $sOut = "", $iNum = 0
For $Num = 0 To $iLine - 1
$iNum += 1
$sOut &= StringFormat("%" & (($iLine - $Num) * 2) & "d", $iNum)
For $Mum = 1 To $Num
$iNum += 1
$sOut &= StringFormat("%4d", $iNum)
Next
$sOut &= @CRLF
Next
ConsoleWrite($sOut & @CRLF)
页:
[1]