declare n number; i number; flag number; begin i:=2; flag:=1; n:=7; for i in 2..n/2 loop if mod(n,i)=0 then flag:=0; exit; end if; end loop; if flag=1 then dbms_output.put_line('prime'); else dbms_output.put_line('not prime'); end if; end; / Output is attached below:
declare
n number;
i number;
flag number;
begin
i:=2;
flag:=1;
n:=7;
for i in 2..n/2
loop
if mod(n,i)=0
then
flag:=0;
exit;
end if;
end loop;
if flag=1
then
dbms_output.put_line(‘prime’);
else
dbms_output.put_line(‘not prime’);
end if;
end;
/
Write a program in PL/SQL to check whether a number is prime or not using goto statement with for loop.
declare n number; i number; flag number; begin i:=2; flag:=1; n:=7; for i in 2..n/2 loop if mod(n,i)=0 then flag:=0; exit; end if; end loop; if flag=1 then dbms_output.put_line('prime'); else dbms_output.put_line('not prime'); end if; end; / Output is attached below:
declare
n number;
i number;
flag number;
begin
i:=2;
flag:=1;
n:=7;
for i in 2..n/2
loop
if mod(n,i)=0
then
flag:=0;
exit;
end if;
end loop;
if flag=1
then
dbms_output.put_line(‘prime’);
else
dbms_output.put_line(‘not prime’);
end if;
end;
/
Output is attached below:
See less