L-L/T - l/CSE Date: 17/08/2017: - Section - A Four Three
L-L/T - l/CSE Date: 17/08/2017: - Section - A Four Three
1. (a) Is the following code fragment valid? What will be the output if so? State your reason.
int a=2, b=5, c ;
c=a+++b;
(c) Write down a program that will take an English letter in upper case as input and will
print two letters after it in the alphabet in lower case. For example, if the user enters D the
output will be f. If the input is Z the output will be b. You are not allowed to use any if-
CSE 101
2. (a) Write down a program that will take a float x and integer n as input and will calculate
the value of the following series. You are not allowed to use any library function(s)
x2 x3 x4 xn
x--+--_ ...--
21 31 41 nl
(b) Write down a program that will take a positive integer n as input and display a
pyramid pattern. The pattern that needs to be displayed for n = 5 is shown below. (12)
*
* II *
I' ,-------*11'11
II *
* """ 1\ II II *
. * * * ~"'" * * ••.
3. ! (a) Giv~n tv:o unsorted ~rrays-Aand. B with size ~ and n, ~rite down two ot~er functions voia1iJ
. umon(lOt A[], lnt B[]' lOt C[], lnt rnJ lnt n) to in:tplement, C = AU Band;
: void intersect(int A[], int B[]' int D[]' int rnJ int n).toimplement D =j (2x9=18)
A n B. As an example, suppose A"'d= {7, 1,5, 2, 3, 6, I} and B = {3, ~)j, .20-';1,
8}. Then C={7, 1,5, :
2,3,6,8,20}, and,D = P, 3, 6}. -",,"
(b) Suppose an array has n positive integers (n ~ 2). Show a code segment to find QCD of
Contd , .. , P/3
=3=
CSE 101
4. (a) Write down the following functions. You are not allowed to use logical operators,
relational operators, if-else or loop. You can only use bitwise operators and arithmetic
(i) . int isNotEqual(int x, intv) returns a if x is equal to V and nonzero if x is not equal to V,
(ii) int coPVABit(int x, int n) copies nth bit to all bit positions, where 1::;;n S 32.
coPVABit(S,3) returns -1 (Le., 1 in all bit positions)
coPVABit(S,2) returns a (Le., a in all bit positions)
(iii) int isNegative(int x) returns a if x is positive and 1 otherwise
(iv) int isSm.aller(int x, int V) returns a if x is not smaller than V and nonzero otherwise . I
.. (v) .. int invertBits(int x, int p, int n) inverts n bits starting from position p of x and returns.,
Assume that, 1 ~ n ::;;32 and a ~ p ::;;31
(b) Write down a function that will take an integer x as parameter and returns after
interchanging all pairs of consecutive bits. Assume the size of integers is 32 bits. Here is
an example: (10)
x = 1011 1111 1110 1010 1001 0000 1000 0001
return value = 0111 1111 1101 0101 0110 0000 0100 0010
SECTION -B
There are FOUR questions in this Section. Answer any THREE questions.
CSE 101
6. (b) A hall management system records information of all students who are either resident
or attached to that hall. The record has the following fields:
Fields . Description
name Name of the student
stdID Student number
DoB Death of birth ofthe student
enrol Date Date of admission into the hall
Room No Room number of the residential student
GPA An alTay contains semester-wise GPA
(a) Write down a suitable data structure to store the above mentioned information of all
whose CGPA is less than 3.0 and occupied seats in the hall. (10)
Write a C function that will retrieve information of all students stored in the hard-disk
into the variable studentList as declared in (b). At the end of the program, you are
required to replace the information stored in the hard-disk with the information recorded
in studentList, which is referred as save operation. Write another C function for save
operation. Both of the function must be written in such a way that a student's information
is considered as a single entity. (Hints: You are not allowed to use fscanO or fprintO
below: (15)
231 187 178 194 203 190
202 195 198 195 204 192
214 197 179 196 200 197
230 190 180 198 201 187
224 219 193 200 201 186
231 123 189 201 203 197
Contd P/f
.~. l
l~
• r
I
= 5=
CSE 101
eoutd .eo Q. No.7(c)
An error matrix in calculated as follows. At first average of all the pixels are calculated
and then error of each pixel is calculated by subtracting the average from the pixel value.
Write a C function to calculate error matrix of a given image. Also write a C function to
calculate the error frequency list, which represents how many times each error occurs.
Arrange the list in ascending order on error values.
8. (a) A binary search tree, abbreviated as BST, is a binary tree where all the element in the
left subtree of a node are less than or equal to the element at that node and all the
A BST can be stored in a ID array where the root of the tree is stored at index 1. node(i)
represent the element stored in the index i. Left child of node(i) is node(2*i) and the right
child of node(i) is node(2*i+ 1). The value of an element -1 in an index means there is no
element at that index. The BST in the Figure is represented in the following array. For
example, 15 is root and hence it is placed in index 1. Left child of 15 is 9, which is placed
in index 2* 1 = 2 and the right child of 15 is 19 which is placed in index 2* 1+ 1 = 3 and so
on.
Index 0 1 2 3 4 5 6 7 8 9 10 11 12
Value -1 15 9 19 -1 12 17 21 -1 -1 -1 -1 -1
(i) Write a recursive C function that will insert a node in the given tree. If the tree does
not exist, inserting a node means that the done become the root of tree, Use the following
function prototype
void BST _insert( int *node, intx); II element x to be inserted into the BST
II and node is name of array.
(ii) The height of a node of the tree is defined as follows: the height of the root is zero. If
a node is at a height of n, then its left and right child are at the height of n+ 1. Write a
recursive C function that will return the height of a given node. The function prototype is
as follows:
int BST_height(int *node, int x); II element x is the element whose height
I I need to be determined
II and node is the name of the array
If the element x is not present in the tree, then -1 will be return.
Contd P16
•
=6=
CSE 101
Contd ... Q. No.8
(b) Write down a recursive C function for binary search within a sorted list that returns
the index of the array if the element is found otherwise returns -1. The prototype of the