PL/SQL Program to Check Number is Prime or Not

PL/SQL Program to Check Number is Prime or Not:

declare
no number;
i number;
flag number;
begin
i:=2;
flag:=1;
no:=:no; 
for i in 2..no/2
loop
if mod(no,i)=0
then
flag:=0;
exit;
end if;
end loop;
  dbms_output.put_line('Entered Number is '|| no); 
if flag = 1
then
  dbms_output.put_line('Number is Prime');
else
  dbms_output.put_line('Number is not Prime');
end if;
end;


OUTPUT:

Entered Number is 3
Number is Prime
---------------------------------------
Entered Number is 4
Number is not Prime

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.