Practice Questions
Practice Questions
2. Find how many even Fibonacci numbers are available in the first n
numbers.
Consider the following first n = 14 numbers:
games = {'D','D','A','H','D','H'}
Marching through this list from beginning to end, mark a value with -1 if it
is the greatest magnitude negative yet seen (strictly greater, not equal).
Mark it with a one (1) if it has the greatest magnitude in the positive
direction (strictly greater, not equal). Just use a 0 if neither of these
conditions have been met.
The result for the above example would be:
result = [1 -1 1 0 0 1 0 -1]
8. When would you use disp instead of fprintf? When would you use fprintf
instead of disp?
9. Write a function called isapatient that first prompts the user to enter a
first name, last name, age and gender and then compares with existing
names, ages and genders in a file (called Registered Patients that will be
sent to you). If the inputs entered cannot be found in the file or if any of
the inputs do not correspond (for instance, the first name exists, but the
last name does not), then an error message should be printed (Please
enter a registered patient) and the input prompt should reappear for the
process to start again.
10. Explain what %4.7f means? Give an example of its use in MATLAB (use
MATLAB code to demonstrate this)