Wednesday, April 30, 2025

B.Tech (CS) 2nd Semester - Programming for Problem Solving (ESCS201) Exam Paper - 2024

 

B.Tech (CS) 2nd Semester - Programming for Problem Solving (ESCS201) Exam Paper - 2024

University Details

  • University: Maulana Abul Kalam Azad University of Technology, West Bengal

  • Paper Code: ESCS201

  • Subject: Programming for Problem Solving

  • UPID: 002008

  • Duration: 3 Hours

  • Maximum Marks: 70


Group-A (Very Short Answer Type Questions)

Answer any ten of the following: [1 × 10 = 10]

  1. What will be the output of the following C code?

    c
    Copy
    Download
    #include <stdio.h>
    void main() {
        int a[2][3] = {1, 2, 3, 4, 5};
        int i = 0, j = 0;
        for (i = 0; i < 2; i++)
            for (j = 0; j < 3; j++)
                printf("%d", a[i][j]);
    }
  2. What is the worst-case complexity of bubble sort?

  3. What is the default return type of a function definition in C?

  4. What will be the output of the following C code?

    c
    Copy
    Download
    #include<stdio.h>
    main() {
        int n;
        n = f1(4);
        printf("%d", n);
    }
    f1(int x) {
        int b;
        if (x == 1) return 1;
        else b = x + f1(x - 1);
        return b;
    }
  5. What is the size of a C structure?

  6. What will be the output of the following C code?

    c
    Copy
    Download
    #include<stdio.h>
    int main() {
        int a = 3, *b = &a;
        printf("%d", a * b);
    }
  7. Which language is written in binary codes only?

  8. The C preprocessors are specified with which symbol?

  9. What will be the output of the following C code? (Assume input = 1)

    c
    Copy
    Download
    #include <stdio.h>
    void main() {
        double ch;
        printf("Enter a value between 1 to 2:");
        scanf("%lf", &ch);
        switch (ch) {
            case 1: printf("1"); break;
            case 2: printf("2"); break;
        }
    }
  10. What happens if you assign a value to an array element with a subscript exceeding the array size?

  11. What is the advantage of selection sort over other sorting techniques?

  12. What is the limit for the number of functions in a C program?


Group-B (Short Answer Type Questions)

Answer any three of the following: [5 × 3 = 15]

  1. Write the differences between call by value and call by reference.

  2. Write a program to compute the factorial of a number using recursion.

  3. What is the difference between break and continue statements?

  4. Differentiate between a compiler and an interpreter.

  5. Write a C program to perform addition, subtraction, multiplication, and division of two numbers using a switch-case statement.


Group-C (Long Answer Type Questions)

Answer any three of the following: [15 × 3 = 45]

  1. Describe different types of asymptotic notations used in algorithm complexity analysis.

  2. Write a C program to find the maximum and minimum of some values using a function that returns an array.

  3. Write a program in C to print all palindrome numbers in a given range using a function.

  4. (a) Write an algorithm to sort an array using Merge Sort.
    (b) Calculate the time complexity of Merge Sort.

  5. What are the different types of computers?

  6. Write a program in C to print the factorial of a number.

  7. Write a C program to print the Fibonacci series up to the nth term.


Exam Guidelines

  • Figures in the margin indicate full marks.

  • Candidates must answer in their own words where applicable.

  • Proper formatting and comments are encouraged in programming questions.

End of Paper

********************************

Solutions

************************************

Analysis and Solutions for Programming for Problem Solving (ESCS201) Exam Paper

Group-A Analysis (Very Short Answer Questions)

Topics Covered:

  • C programming fundamentals

  • Arrays and pointers

  • Recursion

  • Sorting algorithms

  • Preprocessors

  • Memory management

Solved Questions:

  1. Output of the 2D array code:

    c
    Copy
    Download
    #include <stdio.h>
    void main() {
        int a[2][3] = {1, 2, 3, 4, 5}; // Partial initialization
        for(int i=0; i<2; i++)
            for(int j=0; j<3; j++)
                printf("%d", a[i][j]);
    }

    Output: 123450
    (Uninitialized elements become 0)

  2. Worst-case complexity of bubble sort:
    Answer: O(n²)

  3. Default return type of function:
    Answer: int (In traditional C, unspecified return types default to int)

  4. Recursive function output:

    c
    Copy
    Download
    n = f1(4) 
    = 4 + f1(3) 
    = 4 + 3 + f1(2) 
    = 4 + 3 + 2 + f1(1) 
    = 4 + 3 + 2 + 1 
    = 10

    Output: 10

  5. Size of C structure:
    Answer: Sum of all members' sizes + padding (platform dependent)

  6. Pointer arithmetic output:

    c
    Copy
    Download
    int a=3, *b=&a;
    printf("%d", a*b); // Invalid operation (int * pointer multiplication)

    Output: Compiler error

  7. Binary-only language:
    Answer: Machine Language

  8. C preprocessor symbol:
    Answer: #

  9. Switch case with double input (input=1):
    Output: 1
    (Though comparing doubles in switch is bad practice)

  10. Array index out of bounds:
    Answer: Undefined behavior (may corrupt memory)

Group-B Solutions (Short Answer Questions)

2. Call by Value vs Call by Reference

Call by ValueCall by Reference
Copies actual parameter valuesPasses memory address
Changes inside function don't affect originalChanges reflect in original
Uses normal variablesUses pointers
void func(int a)void func(int *a)

3. Factorial Using Recursion

c
Copy
Download
#include <stdio.h>

int factorial(int n) {
    if(n == 0) return 1;
    return n * factorial(n-1);
}

int main() {
    printf("Factorial of 5: %d", factorial(5)); // Output: 120
    return 0;
}

4. Break vs Continue

breakcontinue
Exits entire loopSkips current iteration
Used in switch and loopsOnly in loops
while(1){break;}for(i=0;i<5;i++){if(i==2)continue;}

5. Calculator Using Switch-Case

c
Copy
Download
#include <stdio.h>

int main() {
    char op;
    float a, b;
    printf("Enter operator (+, -, *, /): ");
    scanf("%c", &op);
    printf("Enter two numbers: ");
    scanf("%f %f", &a, &b);

    switch(op) {
        case '+': printf("%.2f", a+b); break;
        case '-': printf("%.2f", a-b); break;
        case '*': printf("%.2f", a*b); break;
        case '/': printf("%.2f", a/b); break;
        default: printf("Invalid operator");
    }
    return 0;
}

Group-C Solutions (Long Answer Questions)

7. Asymptotic Notations

NotationMeaningUse Case
O(1)Constant timeArray access
O(log n)LogarithmicBinary search
O(n)LinearSimple loops
O(n²)QuadraticNested loops
O(2ⁿ)ExponentialRecursive Fibonacci

8. Find Max & Min Using Array-Returning Function

c
Copy
Download
#include <stdio.h>

int* findMinMax(int arr[], int size) {
    static int result[2]; // Static to persist after return
    result[0] = result[1] = arr[0]; // min=max=arr[0]
    
    for(int i=1; i<size; i++) {
        if(arr[i] < result[0]) result[0] = arr[i];
        if(arr[i] > result[1]) result[1] = arr[i];
    }
    return result;
}

int main() {
    int arr[] = {3, 1, 9, 4};
    int *res = findMinMax(arr, 4);
    printf("Min: %d, Max: %d", res[0], res[1]);
    return 0;
}

9. Merge Sort Algorithm & Complexity

Algorithm Steps:

  1. Divide array into two halves

  2. Recursively sort each half

  3. Merge the two sorted halves

Time Complexity:

  • Best/Worst/Average Case: O(n log n)

  • Space Complexity: O(n) (auxiliary array needed)

10. Fibonacci Series Program

c
Copy
Download
#include <stdio.h>

void fibonacci(int n) {
    int a=0, b=1, c;
    printf("Fibonacci Series: ");
    for(int i=1; i<=n; i++) {
        printf("%d ", a);
        c = a + b;
        a = b;
        b = c;
    }
}

int main() {
    fibonacci(10); // Prints first 10 terms
    return 0;
}

Key Observations

  1. Paper Focus Areas:

    • 40% on C programming fundamentals

    • 30% on algorithms and complexity

    • 20% on memory management

    • 10% on computer organization

  2. Difficulty Level:

    • Group-A: Basic (direct concept application)

    • Group-B: Intermediate (requires small implementations)

    • Group-C: Advanced (algorithm design and analysis)

  3. Practical vs Theoretical:

    • 60% practical coding questions

    • 40% theoretical concepts

Thanks 
SK Institute




No comments:

Post a Comment