Control Flow and Operators a Write a MATLAB function that re
Control Flow and Operators
(a) Write a MATLAB function that receives three grades and returns the average with the assigned final grade letter (A,B,C,D,F) using the standard curve. [90 - 100 = A, 80 - 89 = B, 70 - 79 = C, 60 - 69 = D, 0 - 59 = F]
(b) Write a user-defined MATLAB function on separate m-file, that compute the factorial of an input number.
(c) Create a main scripts that ask the user for the appropriate input to call the part (a) and (b) functions and outputs the results.
Solution
(a)
MATLAB function code:
function [x] = final_grade_letter(Y)
if Y==\'A\'
disp(\'90 - 100\')
elseif Y==\'B\'
disp(\'80 - 89\')
elseif Y==\'C\'
disp(\'70 - 79\')
elseif Y==\'D\'
disp(\'60 - 69\')
elseif Y==\'F\'
disp(\'0 - 59\')
end
end
sample output
>> final_grade_letter(\'A\')
90 - 100
>> final_grade_letter(\'F\')
0 - 59
>>
(b)
x=input(\'Enter number :\');
f=factorial(x)
sample output is
Enter number :5
f =
120
>>
(c)
ip=input(\'press 1 for grads or press 2 for factorial :\');
if ip==1
x=input(\'Enter grade :\',\'s\');
final_grade_letter(x)
elseif ip==2
fact()
end
sample outputs are
press 1 for grads or press 2 for factorial :1
Enter grade :C
70 - 79
press 1 for grads or press 2 for factorial :2
Enter number :5
f =
120

