In this post I will explain how to get the factorial of
any given number. For that first you need to know what is the procedure to find
the factorial of a number.
To get the factorial of any given number we have to
multiply that number to every number less than that number till 1.
Suppose we have to find the factorial of 5. Then,
factorial(5)=5*4*3*2*1
=120
So in this way we can calculate the factorial of any
number.
If you want to know the procedure to find the Fibonacci
Sequence Click Here
Program Code:
SQL> set serveroutput on
SQL> declare
2 i number(5);
3 j number (5);
4 f number(10);
5 begin
6 i:=&i;
7 f:=1;
8 for j in 1..i
9 loop
10 f:=f*j;
11 end loop;
12 dbms_output.put_line(f);
13 end;
14 .
SQL> /
Output:
Enter value for i: 3
old 6: i:=&i;
new 6: i:=3;
6
PL/SQL procedure successfully completed.
Enter value for i: 5
old 6: i:=&i;
new 6: i:=5;
120
Result: Thus the above program to print the
factorial of a number was executed successfully.
So
above is a simple program how to find Factorial of any given number. If there
is any query regarding anything please comment.
Thanks
thank you for the program:)
ReplyDeletewas of great use to me;
You are welcome
ReplyDeleteThank you for sharing this program is very helpful for me
ReplyDelete