SUNY Geneseo Department of Mathematics
Wednesday, October 21
Math 230 01
Fall 2015
Prof. Doug Baldwin
input
>> input( 'Enter a number ' )
Enter a number 765
ans =
765
>> input( 'Enter a number ' )
Enter a number 3 + sqrt(17)
ans =
7.1231
fprintf
>> x = 3.7
x =
3.7000
>> fprintf( 'Widgets cost %f today\n', x )
Widgets cost 3.700000 today
>> fprintf( 'Widgets cost %f today and %f yesterday\n', x, x-5 )
Widgets cost 3.700000 today and -1.300000 yesterday
>> fprintf( 'Widgets cost %5.2f today and %0.2f yesterday\n', x, x-5 )
Widgets cost 3.70 today and -1.30 yesterday
>> x = 10379
x =
10379
>> fprintf( 'Widgets cost %5.2f today and %0.2f yesterday\n', x, x-5 )
Widgets cost 10379.00 today and 10374.00 yesterday
program creates random number between 0 and 50
user guesses number
if guess matches created number, stop
otherwise get user guess again
n = random number between 1 and 50
a = user input
while a ≠ n
print “you’re wrong” message
a = user input
%{ n = random number between 1 and 50
a = user input
while a ≠ n
print “you’re wrong” message
a = user input
%}
n = randi( 3, 1 );
a = input( 'Guess a number ' );
while ( a ~= n )
fprintf( 'Error, try again\n' );
a = input( 'Guess a number ' );
end