VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - April 2025 Set E
Paper Details
- Subject: Programming Skills Using C
- Subject Code: 204
- Set: E
- 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: Maximum of Three Numbers
Max Marks: 10
Write a C program to create a user defined function max() which accept 3- numbers and return maximum number from them.
1. Comparison Logic
Develop the max() function using conditional statements.
Hint
Use if-else if-else logic to compare the three variables. Return the variable that holds the largest value.
View Solution & Output
#include <stdio.h>
// [1] User-defined function to find max
int max(int a, int b, int c) {
if(a >= b && a >= c)
return a;
else if(b >= c)
return b;
else
return c;
}
int main() {
int x, y, z;
printf("Enter three numbers: ");
scanf("%d %d %d", &x, &y, &z);
// [2] Call function and display
printf("Maximum Number is: %d\n", max(x, y, z));
return 0;
}
Step-by-Step Explanation:
- Initialization: Define a
max()UDF that takes three integer parameters and uses conditional checks to compare them. - Logic Flow: In
main(), read three numbers and pass them as arguments to themax()function. - Completion: The function returns the largest value, which is then displayed to the user.
Q2: Python Pandas CSV Analytics
Max Marks: 10
Create a DataFrame from CSV file which contains following values: Book_no, Book_name, Price, Author. Perform following operations on it:
- Print the values of book name.
- Display book name and author.
- Display the details of book named 'Let us C'.
- Display the details of book at location 3rd.
1. CSV Loading & Selection
Process a book catalog using Pandas indexing and filtering.
Hint
Use pd.read_csv() to load. Use df['col'] or df[['col1', 'col2']] for selection, and df.iloc[2] for the 3rd location (index starts at 0).
View Solution & Output
import pandas as pd
# [0] Create sample CSV for demonstration
data = {
'Book_no': [1, 2, 3, 4],
'Book_name': ['Python Pro', 'Let us C', 'Java Hub', 'C++ Expert'],
'Price': [500, 350, 450, 600],
'Author': ['Guido', 'Y. Kanetkar', 'James', 'Bjarne']
}
pd.DataFrame(data).to_csv('books.csv', index=False)
# [1] Load DataFrame
df = pd.read_csv('books.csv')
# [i] Print values of book name
print("--- Book Names ---")
print(df['Book_name'])
# [ii] Display book name and author
print("\n--- Name and Author ---")
print(df[['Book_name', 'Author']])
# [iii] Details of 'Let us C'
print("\n--- Details of 'Let us C' ---")
print(df[df['Book_name'] == 'Let us C'])
# [iv] Details of book at 3rd location
print("\n--- 3rd Book Record ---")
print(df.iloc[2])
Step-by-Step Explanation:
- Initialization: Create a sample book CSV file and load it into a pandas DataFrame using
read_csv(). - Logic Flow: Select specific columns, filter rows by book name, and access specific records using integer-based indexing with
iloc. - Completion: Print the specific filtered and indexed data as requested by the operations.
Q3: Viva Preparation
Max Marks: 5
Potential Viva Questions
- Q: Can a function return more than one value in C?
- A: Directly, no. But we can use pointers or structures to return multiple data points indirectly.
- Q: What is the difference between
locandilocin Pandas?- A:
locis label-based (uses row/column names);ilocis integer-position based (uses numeric indices).
- A:
- Q: How does
read_csv()handle headers by default?- A: It assumes the first row of the CSV file contains the column names.
- Q: What is a ternary operator in C? Can we use it for finding max of 3?
- A: It is a shorthand for
if-else(condition ? expr1 : expr2). Yes:max = (a>b) ? (a>c?a:c) : (b>c?b:c).
- A: It is a shorthand for
- Q: How do you filter a DataFrame for multiple conditions?
- A: Using bitwise operators
&(AND) or|(OR), e.g.,df[(df['Price'] > 400) & (df['Author'] == 'Guido')].
- A: Using bitwise operators
- Q: What is
df.info()used for?- A: It provides a summary of the DataFrame including column names, data types, and non-null counts.
Common Pitfalls
- Indexing Bias: Remember that
iloc[3]gives the 4th row. For the 3rd row, useiloc[2]. - File Not Found: Ensure
books.csvexists in the script's directory before callingread_csv.
Quick Navigation
Related Solutions
| Set | Link |
|---|---|
| Set A | Solutions |
| Set B | Solutions |
| Set C | Solutions |
| Set D | Solutions |
| Set E | Current Page |
| Set F | Solutions |
Last Updated: April 2026