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 B

Paper Details
  • Subject: Programming Skills Using C
  • Subject Code: 204
  • Set: B
  • 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: Matrix Operations

Max Marks: 10

Write a C program to accept the values of 3x3 matrix and perform following operations on it.

  1. Display transpose of matrix
  2. Display sum of diagonal of matrix

1. Matrix Input & Structure

Accept a 3x3 grid from the user.

Hint

Use a 2D array matrix[3][3] and nested for loops to read values.

View Solution & Output
#include <stdio.h>

int main() {
int matrix[3][3], i, j, sum = 0;

// [1] Input values
printf("Enter elements for 3x3 matrix:\n");
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
printf("Element [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}

// [2] Transpose Logic
printf("\nTranspose of Matrix:\n");
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
printf("%d\t", matrix[j][i]);
}
printf("\n");
}

// [3] Diagonal Sum Logic
for(i = 0; i < 3; i++) {
sum += matrix[i][i];
}
printf("\nSum of Diagonal Elements: %d\n", sum);

return 0;
}

Step-by-Step Explanation:

  1. Initialization: Declare a 3x3 integer matrix and a sum variable to store the diagonal total.
  2. Logic Flow: Use nested loops for input, then print the transpose by swapping row/column indices and add matrix[i][i] to sum.
  3. Completion: Output the resulting transpose matrix and the sum of its diagonal elements.

Output:

Enter elements for 3x3 matrix:
...
Transpose of Matrix:
1 4 7
2 5 8
3 6 9

Sum of Diagonal Elements: 15

Q2: Python Data Frame Analysis

Max Marks: 10

Write a Python program to create a data frame from a dictionary and display it. Dictionary contains information of students like Roll No, Name and Total marks (out of 500). Also display student records in descending order of Total marks.

1. DataFrame Creation & Sorting

Convert student records into a table and sort them by performance.

Hint

Use pd.DataFrame(dict) to create the table and df.sort_values(by='Total marks', ascending=False) for sorting.

View Solution & Output
import pandas as pd

# [1] Create dictionary
student_dict = {
'Roll No': [101, 102, 103, 104, 105],
'Name': ['Rahul', 'Priya', 'Amit', 'Sia', 'Aryan'],
'Total marks': [450, 380, 490, 410, 425]
}

# [2] Convert to DataFrame
df = pd.DataFrame(student_dict)
print("Original DataFrame:")
print(df)

# [3] Sort in descending order
sorted_df = df.sort_values(by='Total marks', ascending=False)
print("\nStudents Sorted by Marks (Descending):")
print(sorted_df)

Step-by-Step Explanation:

  1. Initialization: Import pandas and create a student dictionary with Roll No, Name, and Total Marks.
  2. Logic Flow: Convert the dictionary into a DataFrame and use sort_values with ascending=False to sort by marks.
  3. Completion: Display the original DataFrame followed by the sorted results in descending order.

Q3: Viva Preparation

Max Marks: 5

Potential Viva Questions
  1. Q: What is a Transpose of a matrix?
    • A: A matrix formed by interchanging its rows and columns.
  2. Q: How do you identify diagonal elements in a 2D array?
    • A: Elements where the row index and column index are equal (e.g., matrix[i][i]).
  3. Q: Why use Pandas DataFrames instead of just Dictionaries?
    • A: DataFrames provide more powerful features for sorting, filtering, and statistical analysis.
  4. Q: What is the maximum size of an array in C?
    • A: It depends on the available memory (stack/heap size) and the compiler, but typically it is limited by the maximum value of the size_t type.
  5. Q: How do you handle multiple sorting columns in Pandas?
    • A: Pass a list to by, e.g., df.sort_values(by=['Marks', 'Name'], ascending=[False, True]).
  6. Q: What does df.head(2) do?
    • A: It returns only the first 2 rows of the DataFrame.
Common Pitfalls
  • Loop Indices: Ensure nested loops use different variables (e.g., i and j) to avoid infinite loops or logic errors.
  • Library Import: Don't forget import pandas as pd at the start of your Python script.

Quick Navigation

SetLink
Set ASolutions
Set BCurrent Page
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