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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by