can anyone know to write a mathlab function that takes an input integer "n" and computes the following
1 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
Prasanth Sikakollu
2019-6-10
Using While loop, try the following function:
function result = getFacWhile(n)
result = 1;
while n ~= 1
result = result * n;
n = n - 1;
end
end
Using for loop, try the following function:
function result = getFacWFor(n)
result = 1;
for i = 2:n
result = result * i;
end
end
Hope this helps
1 个评论
Steven Lord
2019-6-10
Please don't post solutions to homework problems (or problems that sound like they're probably homework problems) unless the person asking the question has shown the effort they've put in place first.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!