Info

This question is closed. Reopen it to edit or answer.

How can a teacher answer this ?

3 views (last 30 days)
Emma Swaggy
Emma Swaggy on 22 May 2017
Commented: Thomas Nguyen on 8 Apr 2018
Write a program that will display the result of n! using a loop. For example, if the user enters 5 for n, the program should display “factorial of is 120”.
  1 Comment
Thomas Nguyen
Thomas Nguyen on 8 Apr 2018
function[] = factorial()
n=input('Enter value n: ');
fac=1;
for i=1:n
fac=fac*i;
end
disp(['The factorial of ',num2str(n),' is: ',num2str(fac)])
end%factorial()

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!