FACTORIAL OF THE GIVEN NUMBER


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

ALGORITHM:

Algorithm for main function:
Step 1: Accept he value of n in the function FACT two parameters.
Step 2: Compute the factorial using for loop.
Step 3: Return the output to main function using return statement.
Step 4: Stop the program.

Algorithm for main program:
Step 1: Get the value of n, factorial to be found.
Step 2: Call the function fact with parameters.
Step 3: Display the factorial of a given number.
Step 4: 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 /
Previous
Next Post »

Still not found what you are looking for? Try again here.