For and while loops
3 次查看(过去 30 天)
显示 更早的评论
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
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!