This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: SolutionsCS100M 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= k-x end 2 SolutionsCS100M 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
- Spring '07