**AIM:**

To write PL/SQL program using function and procedure..

**FACTORIAL OF THE GIVEN NUMBER :**

Algorithm for main function:

Accept he value of n in the function FACT two parameters.

Compute the factorial using for loop.

Return the output to main function using return statement.

Stop the program.

Algorithm for main program :

Get the value of n, factorial to be found.

Call the function fact with parameters.

Display the factorial of a given number.

Stop the program.

**PROGRAM:**

**Function:**

SQL> create or replace function fact(n number) return number is

2 i number(3);

3 f number:=1;

4 begin

5 for i in 1..n

6 loop

7 f:=f*i;

8 end loop;

9 return(f);

10 end fact;

11 /

Function created.

**Main program:**

SQL> set serveroutput on

SQL> declare

2 f number(3);

3 n number(3):=&n;

4 begin

5 f:=fact(n):

6 dbms_output.put_line('factorial='f);

7 end;

8 /