PL/SQL Package to find Factorial and Armstrong Number

PL/SQL Package to find Factorial and Armstrong Number:


/** CREATING PACKAGE **/
create or replace package fact_arm is
function factorial(n in number) return number;
procedure armstr(no in number);
end;
/** CREATING PACKAGE BODY **/
create or replace package body fact_arm is
function factorial(n in number) 
return number is f number;
begin
f:=1;
for i in 1..n
loop
f:=f*i;
end loop;
return(f); 
end;

procedure armstr(no in number) is
str varchar(15);
dig number;
sod number;
begin
sod:=0;
for i in 1..length(no)
loop
dig:=substr(no,i,1);
dig:=dig*dig*dig;
sod:=sod+dig;
end loop;
if(sod = no) then
dbms_output.put_line('Armstrong Number');
else
dbms_output.put_line('Not Armstrong number');
end if;
end;
end fact_arm;

Calling Package:

begin
fact_arm.armstr(173);
end;
--------------------------------------------------
select fact_arm.factorial(5) from dual;



Leave a Reply

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

5 × 4 =