All Type Coding

Search Here

Armstrong number between 0 to 1000 in sql server

Declare @sl int=0;
while(@sl<1000)
begin
declare @num int,@n1 int,@temp int=''
,@rm int,@pow int

set @num=@sl;
set @pow=LEN(@num)
set @n1=@num
while(@num>0)
begin
set @rm=@num%10
set @num=@num/10
set @temp=power(@rm,@pow)+@temp
end
if(@temp=@n1)
begin

print @n1;
end
set @sl+=1;
end

print'0 to 1000 armstrong number'

OutPut will be:
0
1
2
3
4
5
6
7
8
9
153
370
371
407
0 to 1000 armstrong number






No comments :

Post a Comment