function output = calculateFactorial(N)
output = N*(N-1);
if (length(N) = N < 1 || N > 1)
output = 'Error; N must be a single number and not an array';
elseif N < 0
output = 'Error; N must be greater than Zero';
elseif rem(N,1) ~= 0
output = 'Error; Intger must be whole number';
elseif N == 0
output = 1;
end
struggling with these functions. If i ommit line 2, theres then a mistake on line 3 where there is an incoorrect use of '='. I need help wrapping my head around my mistakes.

 採用された回答

madhan ravi
madhan ravi 2021 年 2 月 27 日

0 投票

if length(N) > 1

3 件のコメント

Jacob Smith
Jacob Smith 2021 年 2 月 27 日
編集済み: Jacob Smith 2021 年 2 月 27 日
I've tried this and it is still an error. This time its not specific to what the error may be. Now it is just,' Error in calculateFactorial (line 2)
if length(N) > 1.'
I've also tried, if length(N) ~= 1, to the same result.
madhan ravi
madhan ravi 2021 年 2 月 27 日
編集済み: madhan ravi 2021 年 2 月 27 日
output = calculateFactorial(1.1)
output = 'Error; Intger must be whole number'
output = calculateFactorial(-1 : 3)
output = 'Error; N must be a single number and not an array'
output = calculateFactorial(-1)
output = 'Error; N must be greater than Zero'
output = calculateFactorial(3)
output = 6
function output = calculateFactorial(N)
output = N .* (N-1);
if length(N) > 1
output = 'Error; N must be a single number and not an array';
elseif N < 0
output = 'Error; N must be greater than Zero';
elseif rem(N,1) ~= 0
output = 'Error; Intger must be whole number';
elseif N == 0
output = 1;
end
end
Jacob Smith
Jacob Smith 2021 年 2 月 27 日
編集済み: Jacob Smith 2021 年 2 月 27 日
Ok, I got it figuerd out now, the error is from not having an N value plugged in. *inserts face into palm* Thanks for the help! It feels good to know that i wasnt too far off.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2020b

質問済み:

2021 年 2 月 27 日

編集済み:

2021 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by