Skip to content

VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - 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.

flowchart TD
start[Start Function]
comp1[is a GT b AND a GT c?]
ret_a[Return a]
comp2[is b GT c?]
ret_b[Return b]
ret_c[Return c]

start --> comp1
comp1 -- "Yes" --> ret_a
comp1 -- "No" --> comp2
comp2 -- "Yes" --> ret_b
comp2 -- "No" --> ret_c
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: 1. Initialization: Define a max() UDF that takes three integer parameters and uses conditional checks to compare them. 2. Logic Flow: In main(), read three numbers and pass them as arguments to the max() function. 3. 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: 1. Print the values of book name. 2. Display book name and author. 3. Display the details of book named 'Let us C'. 4. 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).

flowchart TD
load[Read CSV]
df[Load into DataFrame]
sel[Column Selection]
filt[Filter by Name]
iloc[Access by Index]

load --> df
df --> sel
df --> filt
df --> iloc
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: 1. Initialization: Create a sample book CSV file and load it into a pandas DataFrame using read_csv(). 2. Logic Flow: Select specific columns, filter rows by book name, and access specific records using integer-based indexing with iloc. 3. Completion: Print the specific filtered and indexed data as requested by the operations.

Q3: Viva Preparation

Max Marks: 5

Potential Viva Questions
  1. Q: Can a function return more than one value in C?
  2. A: Directly, no. But we can use pointers or structures to return multiple data points indirectly.
  3. Q: What is the difference between loc and iloc in Pandas?
  4. A: loc is label-based (uses row/column names); iloc is integer-position based (uses numeric indices).
  5. Q: How does read_csv() handle headers by default?
  6. A: It assumes the first row of the CSV file contains the column names.
  7. Q: What is a ternary operator in C? Can we use it for finding max of 3?
  8. A: It is a shorthand for if-else (condition ? expr1 : expr2). Yes: max = (a>b) ? (a>c?a:c) : (b>c?b:c).
  9. Q: How do you filter a DataFrame for multiple conditions?
  10. A: Using bitwise operators & (AND) or | (OR), e.g., df[(df['Price'] > 400) & (df['Author'] == 'Guido')].
  11. Q: What is df.info() used for?
  12. 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, use iloc[2].
  • File Not Found: Ensure books.csv exists in the script's directory before calling read_csv.

Quick Navigation

Set Link
Set A Solutions
Set B Solutions
Set C Solutions
Set D Solutions
Set E Current Page
Set F Solutions

Last Updated: April 2025