PL/SQL Program for Armstrong Number


An Armstrong number is an integer such that the sum of the cubes of its digits is equal to the number itself.
For example, 153 is an Armstrong number since 1**3 + 5**3 + 3**3 = 153.


PL/SQL Program for Armstrong Number


declare
num number:=153;
sum1 number:=0;
rem number;
len number;
temp number;

begin
temp:=num;

len:=length(to_char(num));

while num>0
loop
rem:=mod(num,10);
sum1:=sum1+power(rem,len);
num:=trunc(num/10);
end loop;

if temp=sum1

then
dbms_output.put_line('Number is a armstrong number');

else

dbms_output.put_line('Number is not a armstrong number');

end if;

end;

Output:-

 

Leave a Reply

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