日期:2014-05-17 浏览次数:20513 次
--定义参数 declare @n bigint;set @n=20 declare @i bigint;set @i=1 declare @j bigint;declare @k bigint; --定义个表存放结果 declare @table table(id bigint) while (@i<=@n) begin set @j=0;set @k=0 while @j<@i begin set @j=@j+@k;set @k=@k+1 end insert into @table select replicate(@i,@k-1) set @i=@i+1 end --查看结果 select * from @table /* 1 22 33 444 555 666 7777 8888 9999 10101010 1111111111 1212121212 1313131313 1414141414 1515151515 161616161616 171717171717 181818181818 191919191919 202020202020 */
------解决方案--------------------
public static void Out(int n) { for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { int num = 1; while (num <= i) { Console.Write((i - 1) * i / 2 + 1 + j); num++; } Console.Write(" "); } Console.WriteLine(); } }