{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Fall 2007 Prelim 1 Sol

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

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

View Full Document Right Arrow Icon
Solutions--CS100M Spring 2007 Sample Prelim 1 Question 1 ( 20 points; 4 each ) What do the following Matlab program fragments print? Don't worry about the print format. a = 10; b = 20; c = 30; 30 50 60 a = a + b; b = b + c; c = c + a; fprintf(' %d %d %d ', a, b, c); k = 9; while (k > 0) 7 5 3 1 -1 k = k - 2; fprintf(' %d ', k); end for k = 9:-2:0 k = k - 2; 7 5 3 1 -1 fprintf(' %d ', k); end a = 7; b = 5; if ((a < b) || (mod(b, 2) == 1)) a = b; 5 10 else b = a; end fprintf(' %d %d ', a, a+b); y = 2; for k = 1:3 y = y * y 256 end fprintf(' %d ', y) 2
Image of page 1

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

View Full Document Right Arrow Icon