ESC 101: Fundamentals of Computing Name Roll No Dept. Section
ESC 101: Fundamentals of Computing Name Roll No Dept. Section
ESC 101: Fundamentals of Computing Name Roll No Dept. Section
Name 75 marks
Roll No Dept. Section Page 1 of 8
Instructions:
1. This question paper contains 4 pages (8 sides of paper). Please verify.
2. Write your name, roll number, department and section on every sheet of this booklet.
3. Write your final answers neatly with a blue/black pen. Pencil marks may get smudged.
Q1. Write T or F for True/False (write only in the box on the right hand side) (18x1=18marks)
A E1EC
B F87B
C F1EC #include<stdio.h>
int main(){
D E17B
int m=9900,n=13;
while(n!=0){
2.2 What will be the output of the program shown the right? int temp = m;
m = n;
A 7
n = temp%n;
B 100 }
C 761 printf("%d",m);
return 0;
D None of the above }
2.3 Which of the following statements is correct?
unsigned unsigned int a = 100; is a #include<stdio.h>
A int main(){
valid C statement
unsigned char x = 255;
Subtracting an integer from a character
B unsigned short a = x*256+260;
variable is not a valid operation
printf("%d",a);
Assuming short requires 2 bytes, the
C return 0;
output of C code on the right will be 4
}
D Every character array is also a string
2.4 Let a,b are integer variables. How many of the empty if statements in the table below will
give a compilation error?
A 6 if(b==0 || a= 1); if(b?0:a=1);
if(b?a=1:0); if(a=1 || b==0);
B 5 if(a=1==b=1); if(a==1=b==1);
C 4 if(return 0); if(a =+ 1);
D 3
Q3. Fill in the circles next to ALL CORRECT options (many may be correct). (5x3=15marks)
3.1 Which of the following are valid relational/logical expressions that can be used without
compilation error or run-time error, as the testing condition of an if-else statement? Assume that
a = b = c = 1 are integer variables.
A (a > b) || (a/0)
B ++a = b
C a >= c || a <= b
D 4%-3
3.4 Which of these are valid case labels for a switch statement, given that i=2 is an int variable?
A 3/5+5*9%2
B ‘0’
C (float)7
D i
3.5 Consider an array int arr1[] = {1,2,3,4}; Which of these will not give a compile/runtime error?
4.4 Write down the output for the given input in the space provided
Example:
INPUT: cbacabd
OUTPUT: 5
Explanation: Iterate over the string “cbacabd”. Initially, centre of the palindrome substring is “c”,
and the max length of odd length palindrome is 1. In next iteration, “b” is the centre, but “c” !=
“a”, thus max length is again 1. We keep on iterating like this and we get to the fourth character
“c” for which left characters are equal to corresponding right characters up to first “c” != “d”, thus
the max length of odd length palindrome is 5. In further iterations, we will not get length greater
than this.
ESC 101: Fundamentals of Computing Mid-sem Exam (16 Sep 2019)
Name 75 marks
Roll No Dept. Section Page 7 of 8
5.2 The following program was written to read a sorted (ascending) array of integers and print
the number of duplicate(skipped) elements, and the unique elements in the array in decreasing
order along with their index.
Example:
Input Output
5 skipped:2
22344 3:4
2:3
1:2
However, the current code contains some errors which you need to correct. First write down
what output will this incorrect program give on the given inputs. You can also write output as
Compilation Error, Time Limit Exceeded, or, Other Error. Then correct the program by
pointing out line numbers and corrections to those line numbers. Frivolous and unnecessary
corrections may receive negative marks.