Fall 2006 Prelim 1 Sol - Solutions-CS100M Fall 2006 Sample...

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

View Full Document Right Arrow Icon
Solutions—CS100M Fall 2006 Sample Prelim 1 Question 1: (30 points) Part (a): (4 points) What are the final values of variables x and y ? 9 x x= 5; y= 9; x= y; 9 y y= x; Part (b): (4 points) If the following program terminates after execution, what are the final values of variables x and y ? If the following program represents an infinite loop, write the words “infinite loop” across the boxes. -10 x x= 10; y= 0; while ( x>-10 || y<75 ) y= y + 20 + x; x= x – 5; 90 y end Part (c): (5 points) What will be printed when the following script is executed? Output w=1; z= work(y,x); fprintf('w is %d\n', w); fprintf('x is %d\n', x); fprintf('z is %d\n', z); x= x - y; w= x; fprintf('y is %d\n', y); This part is not applicable in Fall ‘07 Question 1 continues on next page 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
Solutions—CS100M Fall 2006 Sample Prelim 1 Question 1, continued Part (d): (8 points: +2 for each correct answer; -1 for each wrong answer; minimum total is 0) True/False: Write the complete word “ true ” or “ false ” on each blank. _false ___ 1. In a selection statement, the else branch must be the last branch unless you write a boolean expression (condition) following the else keyword. “Short circuiting” in programming refers to the early exit from a for -loop by using the This part is not applicable in Fall ‘07 _true ____ 3. It is always possible to replace a for -loop with a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/28/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Page1 / 5

Fall 2006 Prelim 1 Sol - Solutions-CS100M Fall 2006 Sample...

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