Showing posts with label plsql. Show all posts
Showing posts with label plsql. Show all posts

Thursday, 5 November 2015

PLSQL Program to check whether a number is armstrong or not

declare
n number(5);
temp number(5);
r number(3);
s number(5);
begin
n:=&n;
temp:=n;
s:=0;
while(n>0)
loop
r:=n mod 10;
s:= s + (r*r*r);
n:=floor(n/10);
end loop;
if(temp = s) then
dbms_output.put_line(temp ||' is a Armstrong no');
else
dbms_output.put_line(temp ||' is NOT a Armstrong no');
end if;
end;

PL SQL Program to check whether a number is perfect or not

declare
n number;
i number;
tot number;
begin
n:=&n;
tot:=0;
for i in 1..n/2
loop
if(n mod i=0) then
tot:= tot+i;
end if;
end loop;
if(n=tot)then
dbms_output.put_line('Perfect no');
else
dbms_output.put_line('Not a Perfect no');
end if;
end;