Write a pl/sql program for REVERSE NUMBER
declare
num number(5);
i number(5);
r number(5);
begin
num:=#
r:=0;
i:=num;
while(i>0)
loop
r:=(r*10)+mod(i,10);
i:=floor(i/10);
end loop;
dbms_output.put_line('reverse number is '||r);
end;
/
Write a pl/sql program for PERFECT NUMBER
In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum).
declare
num number(5);
s number(5);
i number(5);
temp number(5);
begin
num:=#
s:=0;
temp:=num;
i:=1;
while(i<num)
loop
if(mod(num,i)=0)
then
s:=s+i;
end if;
i:=i+1;
end loop;
if(s=temp)
then
dbms_output.put_line('perfect number');
else
dbms_output.put_line('not perfect number');
end if;
end;
Write a pl/sql program for STRONG NUMBER
If the sum of factorial of the digits in any number is equal the given number then the number is called as STRONG number.
Ex=1! +4! +5!= 1+24+120 = 145
declare
num number(5);
temp number(5);
f number(5);
i number(5);
s number(5);
r number(5);
begin
num:=#
temp:=num;
f:=1;
i:=1;
s:=0;
while(num>0)
loop
r:=mod(num,10);
i:=1;
f:=1;
while(i<=r)
loop
f:=f*i;
i:=i+1;
end loop;
s:=s+f;
num:=floor(num/10);
end loop;
if(s=temp)
then
dbms_output.put_line('strong');
else
dbms_output.put_line('not strong');
end if;
end;
/
Write a pl/sql program to print prime numbers from 1 to 100?
declare
num number(10);
i number(10):=1;
ct number(10);
k number(5):=1;
begin
while(k<=100)
loop
num:=k;
i:=1;
ct:=0;
while(i<=num)
loop
if(mod(num,i)=0)
then
ct:=ct+1;
end if;
i:=i+1;
end loop;
if(ct=2)
then
dbms_output.put_line(num);
end if;
k:=k+1;
end loop;
end;
/
declare
num number(5);
i number(5);
r number(5);
begin
num:=#
r:=0;
i:=num;
while(i>0)
loop
r:=(r*10)+mod(i,10);
i:=floor(i/10);
end loop;
dbms_output.put_line('reverse number is '||r);
end;
/
Write a pl/sql program for PERFECT NUMBER
In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum).
declare
num number(5);
s number(5);
i number(5);
temp number(5);
begin
num:=#
s:=0;
temp:=num;
i:=1;
while(i<num)
loop
if(mod(num,i)=0)
then
s:=s+i;
end if;
i:=i+1;
end loop;
if(s=temp)
then
dbms_output.put_line('perfect number');
else
dbms_output.put_line('not perfect number');
end if;
end;
Write a pl/sql program for STRONG NUMBER
If the sum of factorial of the digits in any number is equal the given number then the number is called as STRONG number.
Ex=1! +4! +5!= 1+24+120 = 145
declare
num number(5);
temp number(5);
f number(5);
i number(5);
s number(5);
r number(5);
begin
num:=#
temp:=num;
f:=1;
i:=1;
s:=0;
while(num>0)
loop
r:=mod(num,10);
i:=1;
f:=1;
while(i<=r)
loop
f:=f*i;
i:=i+1;
end loop;
s:=s+f;
num:=floor(num/10);
end loop;
if(s=temp)
then
dbms_output.put_line('strong');
else
dbms_output.put_line('not strong');
end if;
end;
/
Write a pl/sql program to print prime numbers from 1 to 100?
declare
num number(10);
i number(10):=1;
ct number(10);
k number(5):=1;
begin
while(k<=100)
loop
num:=k;
i:=1;
ct:=0;
while(i<=num)
loop
if(mod(num,i)=0)
then
ct:=ct+1;
end if;
i:=i+1;
end loop;
if(ct=2)
then
dbms_output.put_line(num);
end if;
k:=k+1;
end loop;
end;
/
No comments:
Post a Comment