PL/SQL Program to print odd numbers using for loop
Numbers that cannot be evenly divided by 2 are known as odd numbers. In this program, we will generate a list of odd numbers up to n.
PL/SQL Program to print odd numbers using for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | DECLARE n NUMBER; BEGIN -- get user input DBMS_OUTPUT.PUT_LINE('Enter a number : '); n := &n; DBMS_OUTPUT.PUT_LINE('Odd numbers up to ' || n || ':'); FOR i IN 1..n LOOP IF MOD(i, 2) != 0 THEN -- Check if odd number DBMS_OUTPUT.PUT_LINE(i); END IF; END LOOP; END; / |
Output
Enter a number : 10
Odd numbers up to 10
1
3
5
7
9
Check out our other PL/SQL programs examples