Skip to content

VNSGU BCA Sem 2: Programming Skills Using C (204) Practical Solutions - Set F

Paper Details

  • 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.

Hint

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].

flowchart TD
start[Start]
in_a[Input Matrix A]
in_b[Input Matrix B]
calc[Add a[i][j] + b[i][j]]
out[Display Result Matrix]
done[End]

start --> in_a
in_a --> in_b
in_b --> calc
calc --> out
out --> done
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: 1. Initialization: Declare three 3x3 integer arrays for Matrix A, Matrix B, and their sum. 2. Logic Flow: Read elements for both matrices using nested loops, then calculate sum[i][j] = a[i][j] + b[i][j]. 3. 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.

Hint

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).

flowchart TD
start[Accept Input Text]
init[Empty 'unique' List]
loop[Loop Each Character]
seen[Char in unique?]
add[Add to unique]
show[Print result]

start --> init
init --> loop
loop --> seen
seen -- "No" --> add
seen -- "Yes" --> loop
add --> loop
loop -- "Finished" --> show
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: 1. Initialization: Accept a line of text and initialize an empty string unique_chars to store unique characters. 2. Logic Flow: Iterate through each character of the input and append it to unique_chars only if it is not already present. 3. 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
  1. Q: What are the requirements for Matrix Addition?
  2. A: Both matrices must have the same dimensions (e.g., both 3x3).
  3. Q: How can we remove duplicates using a Set in Python?
  4. A: "".join(set(line)) - however, this will likely lose the original order of characters.
  5. Q: What is the time complexity of the unique character script?
  6. A: \(O(N^2)\) in the string implementation (since in check is linear), or \(O(N)\) if using a Set for the seen check.
  7. Q: How do you declare a 2D array in C?
  8. A: Using data_type array_name[rows][cols]; e.g., int a[3][3];.
  9. Q: What is an f-string in Python?
  10. A: It is a literal string prefixed with 'f' that allows embedding expressions inside curly braces {} for easy formatting.
  11. Q: What happens if you try to add matrices of different sizes?
  12. A: Mathematically it is undefined, and in a program it would lead to logical errors or out-of-bounds array access.

Common Pitfalls

  • 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

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

Last Updated: April 2025