PL/SQL Program to Find Factorial of a Number
Let’s do the PL/SQL Program to Find Factorial of a Number. Factorial are those number which can divide by one or itself only.
for example:
6 = 1 * 2 * 3* 4* 5* 6 = 720
PL/SQL Program to Find Factorial of a Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | DECLARE num NUMBER; fact NUMBER := 1; BEGIN -- get user input DBMS_OUTPUT.PUT_LINE('Enter a number: '); num := # IF num < 0 THEN DBMS_OUTPUT.PUT_LINE('Factorial can't calculated for negative numbers.'); ELSIF num = 0 THEN DBMS_OUTPUT.PUT_LINE('Factorial of 0 is 1.'); ELSE FOR i IN 1..num LOOP fact := fact * i; END LOOP; DBMS_OUTPUT.PUT_LINE('Factorial of ' || num || ' is ' || fact || '.'); END IF; END; / |
Output
Enter a number: 6
Factorial of 6 is 720.
Check out our other PL/SQL programs examples