PL/SQL顺时针输出 n 的平方个数字

sharkdoodoo 2010-07-24 09:25:48
打印输出n的平方个数字,格式如下

如果接收参数是4,则

1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7


用PL/SQL能写么

先求能输出

再求能输出好的格式
...全文
224 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzbbob1985 2010-07-24
  • 打赏
  • 举报
回复
找到这个算法 用拼SQL 的方法 貌似可以强行拼写出来 不过 这种东西在数据库端 写起来 很麻烦
lzbbob1985 2010-07-24
  • 打赏
  • 举报
回复
貌似是螺旋数。。。
  • 打赏
  • 举报
回复
帮顶,期待有高人进入
sharkdoodoo 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luoyoumou 的回复:]
-- 这是啥规律啊?
[/Quote]

顺时针,先从左到右,早上到下,右到左,下到上...
心中的彩虹 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用楼主 longshao_feng 的回复:]
打印输出n的平方个数字,格式如下

如果接收参数是4,则

1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7


用PL/SQL能写么

先求能输出

再求能输出好的格式
[/Quote]

这也太强了吧 呵呵
luoyoumou 2010-07-24
  • 打赏
  • 举报
回复
-- 这是啥规律啊?
sharkdoodoo 2010-07-24
  • 打赏
  • 举报
回复
谢谢各位了!
sharkdoodoo 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xman_78tom 的回复:]
SQL code

set serveroutput on

declare
h pls_integer;
i pls_integer;
j pls_integer;
r pls_integer;
l pls_integer;
b pls_integer;
d pls_integer;
pl pls_integer;
begin
h:=&hei……
[/Quote]


厉害,研究了半天只会用java写

PL/SQL就完全不知如何下手

现在准备细心研究答案了...

谢谢
心中的彩虹 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xman_78tom 的回复:]
SQL code

set serveroutput on

declare
h pls_integer;
i pls_integer;
j pls_integer;
r pls_integer;
l pls_integer;
b pls_integer;
d pls_integer;
pl pls_integer;
begin
h:=&hei……
[/Quote]

很好 这个 楼主就用这个吧 很强
luoyoumou 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xman_78tom 的回复:]
SQL code

set serveroutput on

declare
h pls_integer;
i pls_integer;
j pls_integer;
r pls_integer;
l pls_integer;
b pls_integer;
d pls_integer;
pl pls_integer;
begin
h:=&hei……
[/Quote]

-- 强..........
iqlife 2010-07-24
  • 打赏
  • 举报
回复
楼上的好强。。。。学习了
iqlife 2010-07-24
  • 打赏
  • 举报
回复
强,什么应用啊,既然需要螺旋型算法。。。
xman_78tom 2010-07-24
  • 打赏
  • 举报
回复

set serveroutput on

declare
h pls_integer;
i pls_integer;
j pls_integer;
r pls_integer;
l pls_integer;
b pls_integer;
d pls_integer;
pl pls_integer;
begin
h:=&height;
for i in 1..h loop
for j in 1..h loop
r:=i; d:=0; pl:=j-r;

if (r>h-j+1) then
r:=h-j+1; d:=1; pl:=i-r;
end if;

if (r>h-i+1) then
r:=h-i+1; d:=2; pl:=h-j+1-r;
end if;

if (r>j) then
r:=j; d:=3; pl:=h-i+1-r;
end if;

l:=h-2*(r-1)-1;
b:=(4*h-4)*(r-1)-4*(r-1)*(r-2)+1;

dbms_output.put(to_char(b+l*d+pl,'9999'));
end loop;
dbms_output.new_line;
end loop;
end;
/
sharkdoodoo 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 luoyoumou 的回复:]
-- 呵呵,我知道怎么做啦..........
[/Quote]


真的?分享下~
luoyoumou 2010-07-24
  • 打赏
  • 举报
回复
-- 呵呵,我知道怎么做啦..........

17,378

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧