This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Solutions—CS100M Fall 2007 Prelim 1 Question 1: (25 points) Part (a): (3 points) What are the final values of variables x and y ? 14 x x= 2; y= 7*x; x= y; 14 y Part (b): (3 points) What are the final values of variables x and y ? x= 5; y= 6; 6 x if x<y x= y; y= x; end 6 y if x>y x= 5; y= 6; end Part (c): (3 points) What is the output produced by this script? y = 94 y = 98 y = 100.5 (Just writing the values is fine) x= 12; for k= 100:102 x= x/2; y= kx end 2 Solutions—CS100M Fall 2007 Prelim 1 Question 1, continued Part (d): (8 points) Assume that x is a variable whose value is larger than one. Fill in the loop condition so that the following fragment prints the smallest integer strictly greater than x whose square root is an integer. k= ceil(x); while _______________________________________________ Some possibilities: k==x  sqrt(k)~=floor(sqrt(k)) ~( k>x && sqrt(k)==floor(sqrt(k)) ) k= k+1; end disp(k) Part (e): (8 points) Assume that a , b , c , and d are initialized variables whose values satisfy a < b and c < d . Fill in the condition so that the message is printed if the intervals [...
View
Full
Document
This note was uploaded on 02/28/2008 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell.
 Spring '07
 FAN/VANLOAN

Click to edit the document details