Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - April 2025 Set A

Paper Details
  • Subject: Programming Skills Using C
  • Subject Code: 204
  • Set: A
  • Semester: 2
  • Month/Year: April 2025
  • Max Marks: 25
  • Time Recommendation: 45 Minutes
  • Paper: View Paper | Download PDF

Questions & Solutions

All questions are compulsory

Q1: Factorial UDF

Max Marks: 10

Write a C program to create user define function fact() that returns factorial of given number N to main function.

1. Factorial Function Logic

Develop the fact() function to calculate the factorial using a loop.

Hint

Factorial of $N$ is $1 \times 2 \times \dots \times N$. Use a loop that starts from 1 and multiplies each number. Handle the case for $0! = 1$ correctly.

View Solution & Output
// User-defined function to calculate factorial
int fact(int n) {
if (n == 0 || n == 1) {
return 1;
}
int result = 1;
for (int i = 2; i <= n; i++) {
result = result * i;
}
return result;
}

Step-by-Step Explanation:

  1. Initialization: Initialize result to 1 and check if the input n is 0 or 1.
  2. Logic Flow: Use a for loop from 2 to n, multiplying result by each integer to calculate the factorial.
  3. Completion: Return the final result value to the main function for display.

2. Main Execution Flow

Implement the main() function to accept user input and call the fact() function.

View Solution & Output
#include <stdio.h>

int main() {
int N;

printf("Enter a number: ");
scanf("%d", &N);

if (N < 0) {
printf("Error: Factorial not defined for negative numbers.\n");
} else {
int factorial = fact(N);
printf("Factorial of %d = %d\n", N, factorial);
}

return 0;
}

Step-by-Step Explanation:

  1. Initialization: Declare an integer variable N and prompt the user for input.
  2. Logic Flow: Read the number, validate that it is non-negative, and call the fact() UDF.
  3. Completion: Print the calculated factorial or an error message if the number was negative.

Output:

Enter a number: 5
Factorial of 5 = 120

Q2: Python Student CRUD

Max Marks: 10

Write a Python program to create a dictionary for student data which contain Roll No, Name, Div, Marks and City. Perform Insert, Update and Delete operation on it.

1. Data Initialization & CRUD Operations

Create the student dictionary and navigate through the different operations.

Hint

Start with a dictionary containing the required fields. Use student['new_key'] = value for insert/update and del student['key'] for delete.

View Solution & Output
# Initialize student dictionary
student = {
"Roll No": 101,
"Name": "Rahul Sharma",
"Div": "A",
"Marks": 85,
"City": "Surat"
}

# Display original data
print("Original Student Data:", student)

# INSERT operation
student["Phone"] = "9876543210"
print("After Insert (Phone):", student)

# UPDATE operation
student["Marks"] = 92
print("After Update (Marks):", student)

# DELETE operation
del student["Div"]
print("After Delete (Div):", student)

Step-by-Step Explanation:

  1. Initialization: Define a dictionary student with initial fields like Roll No, Name, and Marks.
  2. Logic Flow: Perform an insert by adding a new key, update an existing value, and delete a key using the del keyword.
  3. Completion: Print the dictionary state after each operation to confirm the CRUD actions.

Expected Output:

Original Student Data: {'Roll No': 101, 'Name': 'Rahul Sharma', 'Div': 'A', 'Marks': 85, 'City': 'Surat'}
After Insert (Phone): {'Roll No': 101, 'Name': 'Rahul Sharma', 'Div': 'A', 'Marks': 85, 'City': 'Surat', 'Phone': '9876543210'}
After Update (Marks): {'Roll No': 101, 'Name': 'Rahul Sharma', 'Div': 'A', 'Marks': 92, 'City': 'Surat', 'Phone': '9876543210'}
After Delete (Div): {'Roll No': 101, 'Name': 'Rahul Sharma', 'Marks': 92, 'City': 'Surat', 'Phone': '9876543210'}

Q3: Viva Preparation

Max Marks: 5

Potential Viva Questions
  1. Q: How does a function return a value in C?
    • A: Using the return statement followed by the value or variable to be sent back to the calling function.
  2. Q: What is a Python Dictionary?
    • A: An unordered collection of data in key-value pairs, where keys must be unique and immutable.
  3. Q: Difference between int fact() and void fact()?
    • A: int fact() returns an integer value, while void fact() does not return any value.
  4. Q: What is Recursion? Can we solve factorial using it?
    • A: Recursion is when a function calls itself. Yes, factorial is a classic example: fact(n) = n * fact(n-1) with base case fact(0)=1.
  5. Q: Are dictionary keys case-sensitive in Python?
    • A: Yes, "Name" and "name" would be treated as two different keys.
  6. Q: What happens if you try to access a dictionary key that doesn't exist?
    • A: Python raises a KeyError. You can use the .get() method to avoid this and return None instead.

Quick Navigation

SetLink
Set ACurrent Page
Set BSolutions
Set CSolutions
Set DSolutions
Set ESolutions
Set FSolutions

Last Updated: April 2026

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir