Quiz 3: Computer Programming (MA511)
Quiz 3: Computer Programming (MA511)
main (){
int a, b, c, d, e;
a = (b = (c = (d = (e = 0))));
printf (“%d %d %d %d %d\n”, a, b + +, c − −, d = 10, e+ = 3);
printf (“%d %d %d %d %d\n”, a, b, c, d = e, e+ = d);
a = b = c = d = e = 0;
printf (“%d %d %d %d %d\n”, a, + +b, − −c, d = 10, e+ = 3);
printf (“%d %d %d %d %d\n”, a, b, c, d+ = e, e = d);
}
main(){
void function(int b[ ][3]){
int a[3][3]= {{1,2,3}, {4,5,6}, {7,8,9}};
++ b;
function(a);
b[1][1] =9;
printf(“%d” , a[2][1]);
}
}
3. What will be the output of the following code if inputs are given any character (i) excluding
and (ii) including ‘Q’ and why ? [4]
main(){
char ch;
do{
switch(ch = getchar()){
default : putchar(ch); break;
case ‘Q’ : ;
}
}while (ch != ’Q’);
}
4. Draw binary search tree where key values of the nodes are given in the following or-
der: 15, 20, 5, 10, 11, 2, 3, 7, 8, 1, 30, 20 , 200 , 10 . (i) Trace path for searching the target
keys: 1, 2, 9, 14. (ii) What is the hight of the tree ? (iii) How many extra node do
you need for making the tree complete ? (iv) Use formula for calculating the total
number of nodes assume the tree is complete. [3+2+1+2+2]
5. Write a subroutine to implement a doubly linked list as a circular list without us-
ing recursion. Assign appropriate links over the doted place in the following skeletal
structure of C program such that doubly circular list will be maintained. [4+3]
main(){
node *p, *q, *r, *s;
p = (node *) malloc(sizeof(node));
q = (node *) malloc(sizeof(node));
typedef struct list {
r = (node *) malloc(sizeof(node));
struct list *prev;
s = (node *) malloc(sizeof(node));
int data;
p→data = 12;
struct list *next;
q→data = 11;
} node;
r→data = 14;
s→data = 5;
..
.
}