CS409P – Introduction to database administrator Total Marks = 20
Assignment No.2 Solution Deadline
Semester: Spring 2025 th
23 of Jun 2025
Please carefully read the following instructions before attempting the assignment Solution.
NOTE
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before submitting copy
paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an Assignment GDB checks your assignment requirement file.
For any query, feel free to Contact at
WhatsApp: +923074960034
Provide by M.JUNAID QAZI
Question No. 1 (10 Marks )
Write PL/SQL code to find the number of ways to arrange 5 books on a shelf (Permutation).
Hint:
nPr = n! / (n - r)!
Here, n = 5, r = 5, and factorial(!) can be calculated using following formula.
5!=5*4*3*2*1
CONTACT ON WHATSAPP
+923074960034
Ansawer:
-- permutation.sql
SET SERVEROUTPUT ON;
DECLARE
n NUMBER := 5;
r NUMBER := 5;
n_fact NUMBER := 1;
n_r_fact NUMBER := 1;
result NUMBER;
BEGIN
-- Calculate n!
FOR i IN 1..n LOOP
n_fact := n_fact * i;
END LOOP;
-- Calculate (n - r)!
FOR i IN 1..(n - r) LOOP
n_r_fact := n_r_fact * i;
END LOOP;
CONTACT ON WHATSAPP
+923074960034
-- Calculate nPr
result := n_fact / n_r_fact;
DBMS_OUTPUT.PUT_LINE('Number of permutations (nPr) = ' || result);
END;
Question No. 2 (10 Marks )
Write PL/SQL code to find the number of ways to choose 2 students out of 6 (Combination).
Hint:
nCr = n! / (r! * (n - r)!)
Here, n = 6, r = 2, and factorial(!) can be calculated using following formula.
5!=5*4*3*2*1
CONTACT ON WHATSAPP
+923074960034
Answer:
-- combination.sql
SET SERVEROUTPUT ON;
DECLARE
n NUMBER := 6;
r NUMBER := 2;
n_fact NUMBER := 1;
r_fact NUMBER := 1;
n_r_fact NUMBER := 1;
result NUMBER;
BEGIN
-- Calculate n!
FOR i IN 1..n LOOP
n_fact := n_fact * i;
END LOOP;
-- Calculate r!
FOR i IN 1..r LOOP
r_fact := r_fact * i;
CONTACT ON WHATSAPP
+923074960034
END LOOP;
-- Calculate (n - r)!
FOR i IN 1..(n - r) LOOP
n_r_fact := n_r_fact * i;
END LOOP;
-- Calculate nCr
result := n_fact / (r_fact * n_r_fact);
DBMS_OUTPUT.PUT_LINE('Number of combinations (nCr) = ' || result);
END;
OUTPUT:
Every Assignment/GDB is change due to unique Student ID so don’t copy
That is truly perfect step by step idea solution get help easily.
Wish you the very best of Luck!
CONTACT ON WHATSAPP
+923074960034