How can a teacher answer this ?

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

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()

답변 (0개)

이 질문은 마감되었습니다.

질문:

2017년 5월 22일

댓글:

2018년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by