HW05_soln - Problem 1: > type get_pick pick = input('Enter...

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

View Full Document Right Arrow Icon
Problem 1: >> type get_pick pick = input('Enter an Integer from 1 to 19: '); success = 0; while ( success == 0 ) % NOTE: I could put a single input statement here and remove % the other two. if ( pick >= 1 & pick <= 19 & floor(pick) == pick) success = 1; fprintf('\nYour Pick is %i\n', pick); else fprintf('Try again!\n'); pick = input('Enter an Integer from 1 to 19: '); end end >> get_pick Enter an Integer from 1 to 19: -5 Try again! Enter an Integer from 1 to 19: 499 Try again! Enter an Integer from 1 to 19: 3.14 Try again! Enter an Integer from 1 to 19: 13 Your Pick is 13
Background image of page 1

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

View Full DocumentRight Arrow Icon
Problem 2: >> type int_series k = input('Please Enter a Positive Integer: '); fprintf('\nSeries: ') while (k ~= 1 ) fprintf('%i, ',k); if ( rem(k,2) == 0 ) k = k/2; % Even else k = 3*k+1; % Odd end end fprintf('%i\n',k); >> int_series Please Enter a Positive Integer: 24 Series: 24, 12, 6, 3, 10, 5, 16, 8, 4, 2, 1 >> int_series Please Enter a Positive Integer: 17 Series: 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 >> int_series
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 05/04/2010 for the course ECO 304K taught by Professor Hickenbottom during the Spring '10 term at University of Texas at Austin.

Page1 / 3

HW05_soln - Problem 1: > type get_pick pick = input('Enter...

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