Write a MATLAB script file that prompts the user to input an

Write a MATLAB script file that prompts the user to input an integer n and executes a code (using for loop) to output the factorial of n (recall factorial of 5 is 1*2*3*4*5).

Solution

n=input(\'Enter a non-negative integer: \');
factorial = 1;

for i=1:n
factorial = factorial*i;
end

disp(factorial);

 Write a MATLAB script file that prompts the user to input an integer n and executes a code (using for loop) to output the factorial of n (recall factorial of 5

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site