Spring 2007 Prelim 1 Sol

Spring 2007 Prelim 1 Sol - Solutions—CS100M Fall 2007...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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= k-x 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.

Page1 / 5

Spring 2007 Prelim 1 Sol - Solutions—CS100M Fall 2007...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online