ENGR 132 - QUIZ7

ENGR 132 - QUIZ7 - limit decrease car_speed by 1mph until...

This preview shows pages 1–6. Sign up to view the full content.

Click to edit Master subtitle style 4/24/11 ENGR 132 Wed/Fri 3:30-5:30

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

View Full Document
4/24/11 Quiz 7 What is displayed in the Matlab command window if the script file to the left is executed? w=1; x=7; while x >= 3 if w == 4 x=2; else x=x-1; end w=w+1; fprintf('w=%i, x=%i\ n',w,x) end
4/24/11 Solution w=3, x=5 w=4, x=4 w=5, x=2 +2 +2for each line +2 +4 for only having the fprintf output all other outputs supressed

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

View Full Document
Click to edit Master subtitle style 4/24/11 ENGR 132 Thurs/Tues 9:30-11:30
4/24/11 Quiz 7 The speed limit on I-65 is 70 mph. Determine if the value stored in a variable car_speed is faster, slower, or equal to the speed limit and indicate so using fprintf statements. For the case where car_speed is faster than the speed

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: limit, decrease car_speed by 1mph until car_speed is at or below the speed limit. 55 4/24/11 Solution if car_speed == 70 fprintf('car speed is equal to speed limit') elseif car_speed < 70 fprintf('car speed is under speed limit') else fprintf('car_speed is over speed limit') while car_speed >70 car_speed = car_speed -1 end end %%% other combinations possible +2 if/elseif/else/end (could use 2 elseifs and no else, need 3 conditional statements) +2 correct conditional statements car_speed==70 car_speed < 70 car_speed >70 +2 using a while loop +2 correct while conditional statement +2 for decreasing car_speed by 1 inside while loop...
View Full Document

{[ snackBarMessage ]}

Page1 / 6

ENGR 132 - QUIZ7 - limit decrease car_speed by 1mph until...

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

View Full Document
Ask a homework question - tutors are online