For and while loops

조회 수: 3 (최근 30일)
Danny Maefengea
Danny Maefengea 2020년 6월 22일
댓글: Walter Roberson 2020년 6월 22일
Hi everyone,
How can I write a Matlab function that takes an input integer n and computes the following
n!=n×(n1)×(n2)×2×1 by using:
The while loop and name it getFacWhile(n).
The for loop and name it getFacFor(n).
  댓글 수: 1
KSSV
KSSV 2020년 6월 22일
What have you tried?

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

채택된 답변

Ashish Azad
Ashish Azad 2020년 6월 22일
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by