Question: Create a function which returns the factorial, x! of the input argument, x. You need to create a UDF to perform the task. The function

Create a function which returns the factorial, x! of the input argument, x. You need to create a UDF to perform the task. The function should return the factorial of the input argument when it is a non-negative integer, 0, 1, 2,. On the other side, the function must call the intrinsic MATLAB function error() when the input argument is non-integer or negative; an appropriate error message should be displayed to the user. Your function must have help topics and the H1 line

%What I did

disp('help fact: This is a function thatn takes a non negitive integer n which returns the factorial,x of the input argument,x.')

x=input('Enter a non negitive integer ')

function[a] = fact(x)

x=1;

for x<0

error('not an appropriate integer')

for n>0

f=n*f

end

end

return f

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!