Hi everyone,
How can I write a Matlab function that takes an input integer n and computes the following
n!=n×(n−1)×(n−2)⋯ ×2×1 by using:
The while loop and name it getFacWhile(n).
The for loop and name it getFacFor(n).

 채택된 답변

Ashish Azad
Ashish Azad 2020년 6월 22일

0 개 추천

function F = getFacWhile(n)
F=1;
while n>1
F=F*n;
n=n-1;
end
end
function F = getFacWhile(n)
F=1;
for i=1:n
F=F*i;
end
end

댓글 수: 1

Walter Roberson
Walter Roberson 2020년 6월 22일
We recommend against providing complete solutions to homework problems.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

태그

질문:

2020년 6월 22일

댓글:

2020년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by