--也写了个正的 declare @row int,@col int declare @str varchar(100) set @row=1 print ' * 1 2 3 4 5 6 7 8 9' while @row<=9 begin set @col=1 set @str='' set @str=@str+str(@row,2)+' ' while @col<=@row begin set @str=@str+STR(@row*@col,2)+' ' set @col=@col+1 end print @str set @row=@row+1 end
--稍作改动,不知是不是这样倒? declare @row int,@col int declare @str varchar(100) set @row=9 print ' * 1 2 3 4 5 6 7 8 9' while @row>=1 begin set @col=1 set @str='' set @str=@str+str(@row,2)+' ' while @col<=@row begin set @str=@str+STR(@row*@col,2)+' ' set @col=@col+1 end print @str set @row=@row-1 end--样子 * 1 2 3 4 5 6 7 8 9 9 9 18 27 36 45 54 63 72 81 8 8 16 24 32 40 48 56 64 7 7 14 21 28 35 42 49 6 6 12 18 24 30 36 5 5 10 15 20 25 4 4 8 12 16 3 3 6 9 2 2 4 1 1
declare @row int,@col int declare @str varchar(100) set @row=1 print ' 9 8 7 6 5 4 3 2 1 *' while @row<=9 begin set @col=@row set @str=REPLICATE(' ',9-@row) while @col>=1 begin set @str=@str+STR(@row*@col,2)+' ' set @col=@col-1 end set @str=@str+str(@row,2) print @str set @row=@row+1 end 9 8 7 6 5 4 3 2 1 * 1 1 4 2 2 9 6 3 3 16 12 8 4 4 25 20 15 10 5 5 36 30 24 18 12 6 6 49 42 35 28 21 14 7 7 64 56 48 40 32 24 16 8 8 81 72 63 54 45 36 27 18 9 9
declare @row int,@col int declare @str varchar(1000) set @row=1 print ' * 1 2 3 4 5 6 7 8 9' while @row<=9 begin set @col=@row SET @str=''+@row set @str=REPLICATE(' ',@row) while @col<=9 begin set @str=@str+STR(@row*@col,2)+' ' set @col=@col+1 end print @str SET @row=@row+1 end
第一列漏了 补上 declare @row int,@col int declare @str varchar(1000) set @row=1 print '* 1 2 3 4 5 6 7 8 9' while @row<=9 begin set @col=@row SET @str=' '+@row set @str=@str+REPLICATE(' ',@row) while @col<=9 begin set @str=@str+STR(@row*@col,2)+' ' set @col=@col+1 end print @str SET @row=@row+1 end
--也写了个正的
declare @row int,@col int
declare @str varchar(100)
set @row=1
print ' * 1 2 3 4 5 6 7 8 9'
while @row<=9
begin
set @col=1
set @str=''
set @str=@str+str(@row,2)+' '
while @col<=@row
begin
set @str=@str+STR(@row*@col,2)+' '
set @col=@col+1
end
print @str
set @row=@row+1
end
--稍作改动,不知是不是这样倒?
declare @row int,@col int
declare @str varchar(100)
set @row=9
print ' * 1 2 3 4 5 6 7 8 9'
while @row>=1
begin
set @col=1
set @str=''
set @str=@str+str(@row,2)+' '
while @col<=@row
begin
set @str=@str+STR(@row*@col,2)+' '
set @col=@col+1
end
print @str
set @row=@row-1
end--样子
* 1 2 3 4 5 6 7 8 9
9 9 18 27 36 45 54 63 72 81
8 8 16 24 32 40 48 56 64
7 7 14 21 28 35 42 49
6 6 12 18 24 30 36
5 5 10 15 20 25
4 4 8 12 16
3 3 6 9
2 2 4
1 1
declare @str varchar(100)
set @row=1
print ' 9 8 7 6 5 4 3 2 1 *'
while @row<=9
begin
set @col=@row
set @str=REPLICATE(' ',9-@row)
while @col>=1
begin
set @str=@str+STR(@row*@col,2)+' '
set @col=@col-1
end
set @str=@str+str(@row,2)
print @str
set @row=@row+1
end
9 8 7 6 5 4 3 2 1 *
1 1
4 2 2
9 6 3 3
16 12 8 4 4
25 20 15 10 5 5
36 30 24 18 12 6 6
49 42 35 28 21 14 7 7
64 56 48 40 32 24 16 8 8
81 72 63 54 45 36 27 18 9 9
declare @str varchar(1000)
set @row=1
print ' * 1 2 3 4 5 6 7 8 9'
while @row<=9
begin
set @col=@row
SET @str=''+@row
set @str=REPLICATE(' ',@row)
while @col<=9
begin
set @str=@str+STR(@row*@col,2)+' '
set @col=@col+1
end
print @str
SET @row=@row+1
end
declare @row int,@col int
declare @str varchar(1000)
set @row=1
print '* 1 2 3 4 5 6 7 8 9'
while @row<=9
begin
set @col=@row
SET @str=' '+@row
set @str=@str+REPLICATE(' ',@row)
while @col<=9
begin
set @str=@str+STR(@row*@col,2)+' '
set @col=@col+1
end
print @str
SET @row=@row+1
end