PL/SQL Program for Armstrong Number

Here you will get pl/sql program for armstrong number.

A number is said to be an armstrong number if sum of its digits raised to the power n is equal to number itself, where n is total digits in number.

For example 407 is armstrong number as 4+ 03 + 7= 64 + 0 + 343 = 407.

PL/SQL Program for Armstrong Number

declare
    n number:=407;
    s number:=0;
    r number;
    len number;
    m number;
 
begin
    m:=n;

    len:=length(to_char(n));
    
    while n>0
    loop
        r:=mod(n,10);
        s:=s+power(r,len);
        n:=trunc(n/10);
    end loop;
    
    if m=s
    then
        dbms_output.put_line('armstrong number');
    else
        dbms_output.put_line('not armstrong number');
    end if;
    
end;
/

Output

armstrong number

3 thoughts on “PL/SQL Program for Armstrong Number”

Leave a Comment

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