Mid Term Question 241 CSE1111 E ATR
Mid Term Question 241 CSE1111 E ATR
1. (a) Identify and correct errors in the following code segment (below left). [3]
(b) Find output of the following code segment (below right). [3]
2. (a) Rewrite the code segment (below left) using “if … else” without changing the logical meaning. [3]
(b) Manually trace the following code segment (below right) and show all the changes of the [3]
variables i,p, and x in each step.
(c) Draw a flow chart for the given code segment in Q.2(b) (above right). [3]
Page 1 of 2
3. (a) Write a C program to print the following pattern of digit ‘2’. Take n as user input where n is odd [3]
and n>=5.
Sample input n=5
(b) Replace the “outer” while loop with “for” and the “nested” for loop with “while” loop in the [3]
following code without changing the logical meaning of the program.
int i=0, count = 0;
int n = 12345;
while (n != 0) {
printf ("%d", n % 10);
count++;
for(; i<count; i++) {
printf("%d", n/= 10);
}
printf ("\n");
}
4. Manually trace the given code segment below. Show the changes of all the variables i, hi, hlw and array [3]
arr elements in each step.
Write a program which will take input of N x N numbers in a 2D array A. Now swap all the elements [6]
in the first and last column within the array and finally print the array.
Page 2 of 2