TA GC 162 Computer Programming 1
TA GC 162 Computer Programming 1
Note: Use the answer sheet provided to write your answers. Name, ID no, Lecture Section number
and Instructor's name has to be written clearly. All answers should be in pen. Answers in pencil
will not be evaluated. No overwriting is allowed
Use of calculators and Mobile phones is not allowed
Partial marks will not be assigned to any answer in Part A
2. Rearrange the storage systems given below in a proper hierarchy based on the speed of computing of
each system. Ensure that the hierarchy starts with the fastest system.
(Answer should be indicated using alphabets A to G).
A) Optical disk B) Electronic disk C) Registers D) Main memory
E) Magnetic disk F) Magnetic tapes G) Cache
(2)
3. State whether the following statements are True or False:
a) Accessing privileged instruction by user will cause TRAP to operating system.
b) Multiprogramming is an instance where the operating system makes decisions for the
user.
c) A bootstrap program is used to handle interrupts and traps.
d) Synchronous I/O is preferred because it increases system efficiency.
(0.5x4=2)
4. Given below are the various actions that occur when an interrupt occurs. Rearrange the same in the
correct order in which they occur: Answer using alphabets A to E.
A. Control transferred to interrupt-service routine to handle interrupt
B. CPU registers and program counter are loaded again
C. CPU resumes interrupted computation
D. Control transferred from interrupt-service routine
E. Contents of CPU registers & PC are saved
(2)
S. In the Linux OS give commands for:
a. List all the files in a directory named dirS
b. List all the processes of a user with usemame a04
c. Deleting all files with the yes/no option
d. Renaming a fiJe oldfile to newfile
(0.5x4=2)
6. Give in correct order all the phases that occur in an LC3 ADD instruction. (2)
mainO {
int i=45; float c; c=check{i); printf{"c=%f ,c);
}
check (int ch) {
if{ ch>=45)
return (3.14);
else
return (6.28);
} (3)
mainO {
int j, x=O;
for (j=0; j<=5; j++) {
switch 0-1) {
case 0: case -1: x+=1; break; case 1: case 2: case 3: x+=2; break;
default: x+=3;
}
printf{"%d \t" ,x);
}
} (3)
11.What will be the output of following fragment of program code?
mainO{
int x=3, y, z; z = y = x; z = y + = x = - z;
printf{"%d . %d , %d" , x , y, z );
} (3)
main{){
int a=3, b=4; b % = 3 + 4; a * = a + 5; printf{"%d,%d", b, a);
} (3)
Jte: Lecture Section number, Instructor's name has to be written clearly. Write all details on both the
main answer sheet and the supplementary sheets. Every question has to be answered starting from a new
page. Attempt all the subsections of a question sequentially. All answer should be in pen. Answers
in pencil will not be evaluated. Calculations and justification for each answer should be given.
PART-O
1. Obtain the largest number in the list given below. The subscript indicates the base of the number
system for each number.(Justifyyour answerwith propercalculations.)
a) (126)10 b) (1l1l111)2 c) (175)8 d) (81)16 (4.5)
2. An equation written by an ancient civilization has been decoded and is given below:
13+15=31 .
Assume that they followed a positional notation (much like the decimal system that we follow for
example, (25)10 = 2* 1QI"I + 5* 10/\0). Give proper calculations to determine the base of the
number system that they followed. (3.5)
3. C lete the tabl --- bel
- ---
Decimal 16-Bit 2's Complement 16-BitHex (4 Hex Digits)
-748
0000111100001111 (4)
4. Write a program in C to calculate the sum of every third integer starting from 2 upto 100, (a) using
a while statement (b) using a do-while statement (c) using a for statement. (6)
5. Write a C program with a function to calculate the sum of rows of an nxm matrix. Note that
The main program should take the values of nand m from the keyboard.
It should initialize the matrix with values from the keyboard.
It should call the function to calculate the sum of elements of each row.
It should print the original matrix and the result (sum of each row) in a column on the monitor.
The program should be complete with all declarations and initializations. (9)
6. Give the truth table for the logical expression NOT (NOT (A) OR NOT (B.
What single logic gate has the same truth table? (2)
7. Give the truth table for a 4-to-l mux. Implementa 4-to-l mux using only 2-to-l mux blocks. (4)
8. Given below is the circuit for a 4-bit full-adder. Make necessary connections to make it work as a
4-bit full-adderlsubtractor for 2's complement numbers. Describe its working. (4)
n n
--
)C-oR.
o!e --:r..L
I
11 i
{{OF
10. For a certain electrical circuit with inductance L and resistance R, the damped natural
frequency is given by
JH
Frequency= ---
LC 4C2
R2