VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - April 2025 Set F
- Subject: Programming Skills Using C
- Subject Code: 204
- Set: F
- 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 Addition
Max Marks: 10
Write a C program to perform matrix addition of two 3x3 matrices.
1. Matrix Input & Addition Logic
Sum the corresponding elements of two 3x3 grids.
Define three 2D arrays: a[3][3], b[3][3], and sum[3][3]. Add elements at the same position: sum[i][j] = a[i][j] + b[i][j].
View Solution & Output
#include <stdio.h>
int main() {
int a[3][3], b[3][3], sum[3][3], i, j;
printf("Enter elements for Matrix A:\n");
for(i=0; i<3; i++)
for(j=0; j<3; j++)
scanf("%d", &a[i][j]);
printf("Enter elements for Matrix B:\n");
for(i=0; i<3; i++)
for(j=0; j<3; j++)
scanf("%d", &b[i][j]);
// [1] Addition Logic
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
sum[i][j] = a[i][j] + b[i][j];
}
}
printf("\nResultant Matrix (A+B):\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
printf("%d\t", sum[i][j]);
}
printf("\n");
}
return 0;
}
Step-by-Step Explanation:
- Initialization: Declare three 3x3 integer arrays for Matrix A, Matrix B, and their sum.
- Logic Flow: Read elements for both matrices using nested loops, then calculate
sum[i][j] = a[i][j] + b[i][j]. - Completion: Print the final resultant matrix representing the sum of the two input matrices.
Q2: Python Unique String Generator
Max Marks: 10
Write a Python program that accept a line of text (which consist of multiple words) from input device. Remove duplicate characters from it and make a line of text unique.
1. Character Deduplication
Extract and display unique characters from a string while preserving their first appearance.
Use a loop to iterate through the string and append characters to a new list/string only if they haven't been seen before. Alternatively, use a set for speed (though sets don't preserve order).
View Solution & Output
# [1] Accept input
line = input("Enter a line of text: ")
unique_chars = ""
# [2] Remove duplicates preserving order
for char in line:
if char not in unique_chars:
unique_chars += char
print("Original Text:", line)
print("Unique Characters Text:", unique_chars)
Step-by-Step Explanation:
- Initialization: Accept a line of text and initialize an empty string
unique_charsto store unique characters. - Logic Flow: Iterate through each character of the input and append it to
unique_charsonly if it is not already present. - Completion: Display the original text and the new string containing only unique characters in their original order.
Q3: Viva Preparation
Max Marks: 5
Potential Viva Questions
- Q: What are the requirements for Matrix Addition?
- A: Both matrices must have the same dimensions (e.g., both 3x3).
- Q: How can we remove duplicates using a Set in Python?
- A:
"".join(set(line))- however, this will likely lose the original order of characters.
- A:
- Q: What is the time complexity of the unique character script?
- A: $O(N^2)$ in the string implementation (since
incheck is linear), or $O(N)$ if using a Set for theseencheck.
- A: $O(N^2)$ in the string implementation (since
- Q: How do you declare a 2D array in C?
- A: Using
data_type array_name[rows][cols];e.g.,int a[3][3];.
- A: Using
- Q: What is an f-string in Python?
- A: It is a literal string prefixed with 'f' that allows embedding expressions inside curly braces
{}for easy formatting.
- A: It is a literal string prefixed with 'f' that allows embedding expressions inside curly braces
- Q: What happens if you try to add matrices of different sizes?
- A: Mathematically it is undefined, and in a program it would lead to logical errors or out-of-bounds array access.
- Space Handling: Spaces are also characters. If the question implies removing duplicate letters but keeping spaces, you need an extra
if char != ' 'check. - C Array Bounds: In C, always ensure loops stay within the defined dimensions (0 to 2 for size 3).
Quick Navigation
Related Solutions
| Set | Link |
|---|---|
| Set A | Solutions |
| Set B | Solutions |
| Set C | Solutions |
| Set D | Solutions |
| Set E | Solutions |
| Set F | Current Page |
Last Updated: April 2026