sp08sol - Spring 2008 Prelim 1 Solutions Things to watch...

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

View Full Document Right Arrow Icon
Spring 2008 Prelim 1 Solutions Things to watch out for in upcoming exams (and homework). We WILL take points off for these in the future. - Do not comment every line of code! Comments are for clarity; commenting every line just clutters things up! Using meaningful variable names typically reduces the commenting need. Observe the level of commenting shown in these solutions. Do not write meaningless comments such as “this is a loop” or “loop will stop when this condition isn’t true”… - Do not put a semi-colon after an if-CONDITION or an elseif CONDITION: if x>y ; blah elseif x>z ; blah blah end BAD!! No output echo is produced by Matlab here, so there’s no need for the semi-colon. (Output echo is produced only for assignment operations.) And if you like ending a STATEMENT with a semi-colon, then do so only at the end of a statement. “if x>y” on its own is NOT a complete statement (the statement ends after “blah” in this example). This extra semi-colon is poor style in Matlab, but in another language it would be an actual error! 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question 1: (10 points) Part (a): (3 points) What are the final values of variables x and y ? 8 x x= 5; y= 2*x; x= 8; 10 y Part (b): (3 points) What are the final values of variables x and y ? x= 12; y= 1; 11 x if x>5 x= x-y; elseif x>10 1 y x= y; else y= x; end Part (c): (4 points) What is the output produced by this script? 9
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 01/28/2009 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell University (Engineering School).

Page1 / 6

sp08sol - Spring 2008 Prelim 1 Solutions Things to watch...

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