Q:

Write a program in PL/SQL to print the prime numbers between 1 to 50

0

Write a program in PL/SQL to print the prime numbers between 1 to 50.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PL/SQL Code:

DECLARE
    i NUMBER(3);
    j NUMBER(3);
BEGIN
dbms_output.Put_line('The prime numbers are:');
	dbms_output.new_line;
    i := 2;
    LOOP
        j := 2;
        LOOP
            EXIT WHEN( ( MOD(i, j) = 0 )
                        OR ( j = i ) );
            j := j + 1;
        END LOOP;
        IF( j = i )THEN
          dbms_output.Put(i||'   ');							   
        END IF;
        i := i + 1;
        exit WHEN i = 50;
    END LOOP;
	dbms_output.new_line;
END;
/

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now