ID-CODE: _____________
DATE: _____
Instructions:
Answer the questions in the order given. 
You are allowed neither to modify the recorded time nor to go back to previous questions.

Problem 1.  
SET CHRONOMETER AT ZERO. 
Minutes 	Seconds 	100ms of a second 	
0	0	0	

>>> START CHRONOMETER <<<

Consider the C program fragment below

x=a+b;
y=a+1;
while( (y<=3)&&(!(x%2= =0)) )
{
    y=y+1;
    x=x+1;
    if( !(y%2= =0) ) x=x+1;
    y=y+1;
}
y=y+1

(a)	how many times does the body of the while execute if a=0, b=1?. Answer ___
(b) 	how many times does the body of the while execute if a=1, b=0?. Answer ___
(c)	how many times does the body of the while execute if a=1, b=2?. Answer ___
(d)	what is the final value of x if a=1, b=1?. Answer ___

>>> STOP CHRONOMETER AND WRITE DOWN THE TIME RECORDED <<<

Minutes 	Seconds 	100ms of a second 	

Problem 2.  
SET CHRONOMETER AT ZERO. 
Minutes 	Seconds 	100ms of a second 	
0	0	0	

>>> START CHRONOMETER <<<

Consider the C program fragment below

i=a;
for(;i<5;)
{
    y=i+a+1;
    i=i+3;
    a=a+1;
}

(a)	what is the final value of y if a = 0?. Answer ___
(b)	what is the final value of y if a = 2?. Answer ___
(c)	what is the final value of y if a = 3?. Answer ___
(d)	how many times does the body of the for sentence if a =1. Answer ___

>>> STOP CHRONOMETER AND WRITE DOWN THE TIME RECORDED <<<

Minutes 	Seconds 	100ms of a second 	

Problem 3. 
SET CHRONOMETER AT ZERO. 
Minutes 	Seconds 	100ms of a second 	
0	0	0	

>>> START CHRONOMETER <<<

Consider the C program fragment below

i=a;
for(;i<n;)
{
    m=i-1;
    j=m;
    for(;j<n;)
    {
        if( !(j= =i) && (b>0) ) b=b+2;
        else if(!(j= =i)) b=b+1;
        b=b+1;
        j=j+2;
    }
    i=i+1;
}

(a)	what is the final value of b if a=0, n=2, b=0?. Answer ___
(b)	what is the final value of b if a=1, n=2, b=1?. Answer ___
(c)	what is the final value of b if a=0, n=3, b=2?. Answer ___

>>> STOP CHRONOMETER AND WRITE DOWN THE TIME RECORDED <<<

Minutes 	Seconds 	100ms of a second 	

Problem 4. 
SET CHRONOMETER AT ZERO. 
Minutes 	Seconds 	100ms of a second 	
0	0	0	

>>> START CHRONOMETER <<<

Given the C program fragment below

while( i<=7 )
{
    a=i+b+1;
    i=i+1;
    if( !((i+1)%3= =0) ) a=a+1;
    i=i+1;
    if( a%2= =0 ) a=a+1;
}

(a)	what is the final value of a if i=0, b=0?. Answer ___
(b)	what is the final value of a if i=1, b=1?. Answer ___
(c)	what is the final value of a if i=3, b=2?. Answer ___

>>> STOP CHRONOMETER AND WRITE DOWN THE TIME RECORDED <<<

Minutes 	Seconds 	100ms of a second