Thapar Institute of Engineering and Technology, Patiala
Computer Science and Engineering Department
Mid Semester Examination (MST) 2023-24 Even Semester
B.E. II Sem Course Name: Programming for Problem Solving
Course Code: UES103 Date: 19th March, 2024 Time:11:00AM-1:00PM
Maximum Marks: 30 Faculty: Raman, Ravneet, Saif, Rahul, Seemu, Deep Mann,
Tanu, Himika, Mahak, Saurabh
Marks CO BL
Q1. a) Draw a flowchart to find the greatest of three numbers. (3marks) CO1 L2
b) A 4-bit binary number has 2 zeros and 2 ones. (2marks) CO1 L2
(i) List all the possible binary numbers with
these digits
(ii) Convert these numbers to decimal (base
10).
c) Write a C program to search an element in one-dimensional array using (5marks) CO2 L3
Binary Search. Assume that array is already sorted in ascending order.
Q2. a) Write a program to take a number as input from user and generate a new (5marks) CO1 L3
number by replacing all 0’s with 1’s in the number. For example, if
number =201301, the resultant number should be 211311. (Make sure to
store the resultant number in a variable and print the value of that
variable as output..)
b) Write a program in C to find whether the number is odd or even using (2marks) CO1 L3
ternary operator.
c) Write a program using switch case to build a simple calculator with + (3marks) CO1 L3
(addition) – (Subtraction) * (multiplication) and / (division) operations.
Program should run as follows:
Program should run multiple times and every time it should
take a character input from user as Y or N.
If the user input Y, program should ask user to enter two
numbers and a character input as + - * or / and accordingly
perform the said operation.
It should stop executing whenever a user enters N.
Q3. a) Write a program to take (n x m) 2-D array from user. User wants to insert CO2 L3
a new element in this 2-D array. Ask user to input the row and column (5marks)
number where the new value has to be inserted. You have to insert the
new value preserving the previous values i.e. new value should be inserted
and all other values should be shifted one position ahead.
(As the array size will increase after insertion so make sure to initially take
the size of array accordingly. Also, after insertion, if there is a new row
that will be inserted in the new array, all the trailing elements should be
reflected as 0 in that row)
Example,
Original Array: 1 2 3
4 5 6
7 8 9
Position entered by user: 2,3 and value is 28
Output: 1 23
4 5 28
6 7 8
9 0 0
b) Write a program to take a string with spaces as input from user. Program (5marks) CO2 L4
should interchange (swap) only the second and third words of the string
keeping other part of the string intact. For example:
Input= “I am studying programming”
Output= “I studying am programming:
Bloom's Level wise Marks
Distribution
Level 4 Level 2
17% 16%
Level 3
67%