PL/SQL Program for Prime Number

PL/SQL Program for Prime Number


Prime Number:-Prime number is a number if it is divisible by 1 or itself. For example 2, 3, 5, 7, etc are prime numbers


declare
  num number;
  k number;
  flag number;
 
begin
  k:=2;
  flag:=1;
  num:=7;
 
  for k in 2..num/2
  loop
    if mod(num,k)=0
    then
      flag:=0;
      exit;
    end if;
  end loop;
 
  if flag=1
  then
    dbms_output.put_line('Input number is a prime number');
  else
    dbms_output.put_line('Input number is not a prime number');
  end if;
end;
/

Output:-

Input number is a prime number
https://bit.ly/2lgLuJ1 https://bit.ly/2lAbgYW https://bit.ly/2ngU8ry

Leave a Reply

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