{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW05_soln

# HW05_soln - Problem 1 > type get_pick pick = input'Enter an...

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

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

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

View Full Document
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 Please Enter a Positive Integer: 27 Series: 27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158,
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}