Prime Number

Write a program to check prime number using pl/sql

4 comments:

  1. declare
    i number;
    n number;
    begin
    i:=2;
    n:=&a;
    for i in 2..n/2 loop
    if mod(n,i) <> 0 then
    dbms_output.put_line(n||' is a prime number');
    else
    dbms_output.put_line(n||' is not a prime number');
    end if;
    end loop;
    end;
    /

    ReplyDelete
  2. declare
    nm number(3);
    begin
    nm := &p;
    for ij in 2..nm/2 loop
    if mod(nm,ij)<>0 then
    dbms_output.put_line(nm || 'is a prime number');
    else
    dbms_output.put_line(nm || 'is not a prime number');
    end if;
    end loop;
    end;

    ReplyDelete
  3. declare
    n number;
    i number;
    counter number;
    begin
    n:=&n;
    i:=1;
    counter:=0;
    for i in 1..n loop
    if mod(n,i)=0
    then counter:=counter+1;
    end if;
    end loop;
    if counter=2
    then dbms_output.put_line(n||' is a prime No.');
    else
    dbms_output.put_line(n||' is a not prime No.');
    end if;
    end;

    ReplyDelete
  4. Id:201330499

    declare
    n number(10);
    j number(10);
    temp number(10):=1;
    begin
    dbms_output.put_line('Enter your number: ');
    n:=&number_for_prime_check;
    for j in 2..n-1 loop
    if(n mod j)=0 then
    temp:=0;
    exit;
    end if;
    end loop;
    if(temp=1)then
    dbms_output.put_line('Prime number');
    else
    dbms_output.put_line('Not prime number');
    end if;
    end;
    /

    ReplyDelete

Popular Posts