SUNY Geneseo Department of Mathematics
Monday, March 30
Math 230 02
Spring 2015
Prof. Doug Baldwin
if a
statement1 % done if a true
else
statement2 % done if a false
end
if a
statement1 % done if a true
elseif b
statement2 %done if a false and b true
elseif c
...
else
statementn % done if none are true
end
%% Count negative numbers input by user
x = input( 'Enter a number ' );
if x < 0
negatives = negatives + 1;
end
%% Print absolute value of user input
x = input( 'Enter a number ' );
if x >= 0
fprintf( 'The absolute value of %f is %f\n', x, x );
else
fprintf( 'The absolute value of %f is %f\n', x, -x );
end
%% Classify numbers as close to multiples of 3
x = input( 'Enter a number ' );
if x/3 == floor(x/3)
fprintf( '%f is a multiple of 3\n', x );
elseif x/3 - floor(x/3) < 0.5
fprintf( '%f is just past a multiple of 3\n', x );
elseif x/3 - floor(x/3) > 0.5
fprintf( '%f is almost a multiple of 3\n', x );
else
fprintf( '%f is exacty halfway between multiples of 3\n', x );
end