How to print Factorial by PL/SQL

  Factorial

--------------------------------------------

Factorial, in mathematics, the product of all positive integers less than or equal to a given positive 

integer and denoted by that integer and an exclamation point. 

Thus, factorial seven is written 7!, meaning 1 × 2 × 3 × 4 × 5 × 6 × 7.

----------------------Start Codes----------------

set serveroutput on;

declare

v_factorial number := 30;

v_fact_products number := 1;

v_counter number := 1;

v_result clob;

begin

while (v_counter <= v_factorial) loop

v_fact_products := v_fact_products*v_counter;

v_result := v_result||'X'||(v_factorial-v_counter+1);

v_counter := v_counter + 1;

end loop;

dbms_output.put_line(v_factorial||'!='||trim(leading 'X' from v_result)||'='||v_fact_products);

end;

Result: 30!=30X29X28X27X26X25X24X23X22X21X20X19X18X17X16X15X14X13X12X11X10X9X8X7X6X5X4X3X2X1=265252859812191058636308480000000



Comments

Popular posts from this blog

How to create and show html report by ajax callback and print report in Oracle Apex

How to insert and show blob images in form and report of Oracle Apex

CRUD Operation from HTML