PL/SQL Program to print prime numbers from 1 to 100
Here you will learn pl/sql program to print prime numbers from 1 to 100 using mod and SQRT function in pl/sql programming.
PL/SQL Program to print prime numbers from 1 to 100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | DECLARE num NUMBER; i NUMBER; flag BOOLEAN; BEGIN FOR num IN 2..100 LOOP -- run loop from 2 to 100 flag := TRUE; FOR i IN 2..TRUNC(SQRT(num)) LOOP IF MOD(num, i) = 0 THEN flag := FALSE; EXIT; END IF; END LOOP; IF flag THEN DBMS_OUTPUT.PUT_LINE(num || ' is a prime number'); END IF; END LOOP; END; / |
Output
2 is a prime number
3 is a prime number
5 is a prime number
7 is a prime number
11 is a prime number
13 is a prime number
17 is a prime number
19 is a prime number
23 is a prime number
29 is a prime number
31 is a prime number
37 is a prime number
41 is a prime number
43 is a prime number
47 is a prime number
53 is a prime number
59 is a prime number
61 is a prime number
67 is a prime number
71 is a prime number
73 is a prime number
79 is a prime number
83 is a prime number
89 is a prime number
97 is a prime number
Check out our other PL/SQL programs examples