0% found this document useful (0 votes)
13 views2 pages

1 Declare

This document contains code to: 1. Define a function to calculate the factorial of a given number by using a loop to multiply all integers from 1 to the given number. 2. Define a function to calculate the binomial coefficient (nCr) of two given numbers by calling the factorial function and dividing the results. 3. The code is tested by calling the functions and displaying the output.

Uploaded by

Hari Kappera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

1 Declare

This document contains code to: 1. Define a function to calculate the factorial of a given number by using a loop to multiply all integers from 1 to the given number. 2. Define a function to calculate the binomial coefficient (nCr) of two given numbers by calling the factorial function and dividing the results. 3. The code is tested by calling the functions and displaying the output.

Uploaded by

Hari Kappera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1 declare

2 n number(10):=1;
3 begin
4 loop
5 dbms_output.put_line(n);
6 if n>=10 then
7 exit;
8 end if;
9 n:=n+1;
10 end loop;
11* end;
SQL> /
1
2
3
4
5
6
7
8
9
10

PL/SQL procedure successfully completed.

SQL>
SQL> declare
2 fac number :=1;
3 n number := &1;
4 begin
5 while n > 0 loop
6 fac:=n*fac;
7 n:=n-1;
8 end loop;
9 dbms_output.put_line(fac);
10 end;
11 /
Enter value for 1: 8
old 3: n number := &1;
new 3: n number := 8;
40320

PL/SQL procedure successfully completed.

==========================================
create or replace function ncr(n number ,r number) return number is
n1 number:=fact(n);
r1 number:=fact(r);
nr1 number:=fact(n-r);
result number;
begin
dbms_output.put_line(‘NCR facyorial of n and r is’)
result:=(n1)/(r1*nr1);
return result;
end;
/

========================
create or replace function fact(n number) return number is
i number(3);
f number:=1;
begin
for i in 1..n
loop
f:=f*i;
end loop;
return(f);
end fact;

------->procedure execution 54--55

You might also like