要求用指定的字符(*、&等)打印三角形,要求字符的个数变化是:1、3、5、7、9..............
sql
------解决方案--------------------
DECLARE @Count INT=1;
DECLARE @Cols INT=10;
--IF(@Count%2=1)
WHILE @Count<=@Cols
BEGIN
IF(@Count%2=1)
PRINT SPACE((@Cols-@Count)/2)+REPLACE(SPACE(@Count),' ','*')+SPACE((@Cols-@Count)/2)
SET @Count=@Count+1
END
/*
*
***
*****
*******
*********
*/
------解决方案--------------------
DECLARE @Count INT=1;
DECLARE @Cols INT=10;
--IF(@Count%2=1)
WHILE @Count<=@Cols
BEGIN
IF(@Count%2=1)
PRINT SPACE((@Cols-@Count)/2)+REPLACE(SPACE(@Count),' ','*')+SPACE((@Cols-@Count)/2)
SET @Count=@Count+1
END
SET @Count=@Count-2
WHILE @Count>=0
BEGIN
IF(@Count%2=1)
PRINT SPACE((@Cols-@Count)/2)+REPLACE(SPACE(@Count),' ','*')+SPACE((@Cols-@Count)/2)
SET @Count=@Count-1
END
/*
*
***
*****
*******
*********
*********
*******
*****
***
*
*/