求水仙花数,SQL
答案:2 悬赏:10 手机版
解决时间 2021-03-06 07:00
- 提问者网友:美人性情
- 2021-03-05 18:52
求水仙花数,SQL
最佳答案
- 五星知识达人网友:鱼忧
- 2021-03-05 19:29
declare @n as int,@b as int,@s as int,@g as int
set @n=100
while @n<1000
begin
set @b=cast(substring(cast(@n as varchar(3)),1,1) as int)
set @s=cast(substring(cast(@n as varchar(3)),2,1) as int)
set @g=cast(substring(cast(@n as varchar(3)),3,1) as int)
if power(@b,3)+power(@s,3)+power(@g,3)=@n
begin
print @n
end
set @n=@n+1
end
---------------------------------------
运行结果是:
153
370
371
407
set @n=100
while @n<1000
begin
set @b=cast(substring(cast(@n as varchar(3)),1,1) as int)
set @s=cast(substring(cast(@n as varchar(3)),2,1) as int)
set @g=cast(substring(cast(@n as varchar(3)),3,1) as int)
if power(@b,3)+power(@s,3)+power(@g,3)=@n
begin
print @n
end
set @n=@n+1
end
---------------------------------------
运行结果是:
153
370
371
407
全部回答
- 1楼网友:妄饮晩冬酒
- 2021-03-05 20:20
你得用计算机编程才可求得:
153 370 371 407
153 370 371 407
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯