用2层while循环
1 回答
已采纳
习惯受伤
TA贡献885条经验 获得超1144个赞
随手写了一个,笑纳~~~
declare @num int declare @total int declare @max int declare @blank int declare @temp int declare @str varchar(max) set @num = 1 set @total = 8 set @max = @total * 2 + 1 --max columns set @str = '' --result str while @num <= @total * 2 - 1 -- max star num begin set @temp = 0 set @blank = (@max - @num) / 2 --concat left blank while(@temp < @blank) begin set @str = @str + ' ' set @temp = @temp + 1 end set @temp = 0 --concat star while(@temp < @num) begin set @str = @str + '*' set @temp = @temp + 1 end --concat '\r' set @str = @str + CHAR(13) set @num = @num + 2 end print @str
截图看看:
- 1 回答
- 0 关注
- 2416 浏览
添加回答
举报
0/150
提交
取消