首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

请教怎么用PL/SQL 输出杨辉三角。 多谢

2012-08-16 
请问如何用PL/SQL 输出杨辉三角。 谢谢初学者内容写详细点。感激啦!11112113311464115101051161520156117213

请问如何用PL/SQL 输出杨辉三角。 谢谢
初学者内容写详细点。感激啦!
1  
1 1
1 2 1  
1 3 3 1  
1 4 6 4 1  
1 5 10 10 5 1  
1 6 15 20 15 6 1  
1 7 21 35 35 21 7 1  
1 8 28 56 70 56 28 8 1  
1 9 36 84 126 126 84 36 9 1


[解决办法]
这会有时间正好写一个,就是用到了二维数组。

SQL code
declare  type t_type is table of number index by binary_integer;  type tt_type is table of t_type index by binary_integer;  n        number := &n;  tt_array tt_type;begin  tt_array(1)(1) := 1;  tt_array(2)(1) := 1;  tt_array(2)(2) := 1;  for i in 3 .. n loop    tt_array(i)(1) := 1;    for j in 2 .. i - 1 loop      tt_array(i)(j) := tt_array(i - 1) (j - 1) + tt_array(i - 1) (j);    end loop;    tt_array(i)(i) := 1;  end loop;  for i in 1 .. tt_array.count loop    for j in 1 .. i loop      dbms_output.put(tt_array(i) (j));      dbms_output.put(' ');        end loop;    dbms_output.put_line('');  end loop;end; 

热点排行