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.
- Display transpose of matrix
- 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:
- Initialization: Declare a 3x3 integer matrix and a
sumvariable to store the diagonal total. - Logic Flow: Use nested loops for input, then print the transpose by swapping row/column indices and add
matrix[i][i]tosum. - 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:
- Initialization: Import pandas and create a student dictionary with Roll No, Name, and Total Marks.
- Logic Flow: Convert the dictionary into a DataFrame and use
sort_valueswithascending=Falseto sort by marks. - Completion: Display the original DataFrame followed by the sorted results in descending order.
Q3: Viva Preparation
Max Marks: 5
Potential Viva Questions
- Q: What is a Transpose of a matrix?
- A: A matrix formed by interchanging its rows and columns.
- 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]).
- A: Elements where the row index and column index are equal (e.g.,
- Q: Why use Pandas DataFrames instead of just Dictionaries?
- A: DataFrames provide more powerful features for sorting, filtering, and statistical analysis.
- 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_ttype.
- A: It depends on the available memory (stack/heap size) and the compiler, but typically it is limited by the maximum value of the
- 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]).
- A: Pass a list to
- 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.,
iandj) to avoid infinite loops or logic errors. - Library Import: Don't forget
import pandas as pdat the start of your Python script.
Quick Navigation
Related Solutions
| Set | Link |
|---|---|
| Set A | Solutions |
| Set B | Current Page |
| Set C | Solutions |
| Set D | Solutions |
| Set E | Solutions |
| Set F | Solutions |
Last Updated: April 2026