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]
What will be the output of the following C code?
#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]); }
What is the worst-case complexity of bubble sort?
What is the default return type of a function definition in C?
What will be the output of the following C code?
#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; }
What is the size of a C structure?
What will be the output of the following C code?
#include<stdio.h> int main() { int a = 3, *b = &a; printf("%d", a * b); }
Which language is written in binary codes only?
The C preprocessors are specified with which symbol?
What will be the output of the following C code? (Assume input = 1)
#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; } }
What happens if you assign a value to an array element with a subscript exceeding the array size?
What is the advantage of selection sort over other sorting techniques?
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]
Write the differences between call by value and call by reference.
Write a program to compute the factorial of a number using recursion.
What is the difference between
breakandcontinuestatements?Differentiate between a compiler and an interpreter.
Write a C program to perform addition, subtraction, multiplication, and division of two numbers using a
switch-casestatement.
Group-C (Long Answer Type Questions)
Answer any three of the following: [15 × 3 = 45]
Describe different types of asymptotic notations used in algorithm complexity analysis.
Write a C program to find the maximum and minimum of some values using a function that returns an array.
Write a program in C to print all palindrome numbers in a given range using a function.
(a) Write an algorithm to sort an array using Merge Sort.
(b) Calculate the time complexity of Merge Sort.What are the different types of computers?
Write a program in C to print the factorial of a number.
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:
Output of the 2D array code:
#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)Worst-case complexity of bubble sort:
Answer: O(n²)Default return type of function:
Answer:int(In traditional C, unspecified return types default to int)Recursive function output:
n = f1(4) = 4 + f1(3) = 4 + 3 + f1(2) = 4 + 3 + 2 + f1(1) = 4 + 3 + 2 + 1 = 10
Output:
10Size of C structure:
Answer: Sum of all members' sizes + padding (platform dependent)Pointer arithmetic output:
int a=3, *b=&a; printf("%d", a*b); // Invalid operation (int * pointer multiplication)
Output: Compiler error
Binary-only language:
Answer: Machine LanguageC preprocessor symbol:
Answer:#Switch case with double input (input=1):
Output:1
(Though comparing doubles in switch is bad practice)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 Value | Call by Reference |
|---|---|
| Copies actual parameter values | Passes memory address |
| Changes inside function don't affect original | Changes reflect in original |
| Uses normal variables | Uses pointers |
void func(int a) | void func(int *a) |
3. Factorial Using Recursion
#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
break | continue |
|---|---|
| Exits entire loop | Skips current iteration |
Used in switch and loops | Only in loops |
while(1){break;} | for(i=0;i<5;i++){if(i==2)continue;} |
5. Calculator Using Switch-Case
#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
| Notation | Meaning | Use Case |
|---|---|---|
| O(1) | Constant time | Array access |
| O(log n) | Logarithmic | Binary search |
| O(n) | Linear | Simple loops |
| O(n²) | Quadratic | Nested loops |
| O(2ⁿ) | Exponential | Recursive Fibonacci |
8. Find Max & Min Using Array-Returning Function
#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:
Divide array into two halves
Recursively sort each half
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
#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
Paper Focus Areas:
40% on C programming fundamentals
30% on algorithms and complexity
20% on memory management
10% on computer organization
Difficulty Level:
Group-A: Basic (direct concept application)
Group-B: Intermediate (requires small implementations)
Group-C: Advanced (algorithm design and analysis)
Practical vs Theoretical:
60% practical coding questions
40% theoretical concepts
No comments:
Post a Comment