PL/SQL Program to Check Number is Armstrong Number or Not

PL/SQL Program to Check Number is Armstrong Number or Not:

declare
no number;
arm number;
len number;
c number;
begin
no:=:no;
arm:=0;
len:=length(no);
for i in 1..len
loop
c:=substr(no,i,1);
arm:=arm + (c*c*c);
end loop;
dbms_output.put_line('Entered number is '||no);
if(arm = no) then
dbms_output.put_line('Number is Armstrong');
else
dbms_output.put_line('Number is Not Armstrong');
end if;
end;

OUTPUT:

Entered number is 153
Number is Armstrong
----------------------------------------------------
Entered number is 1532
Number is Not Armstrong

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.