Using a "while" loop to calculate a factorial

10 次查看(过去 30 天)
Use a while loop to calculate f=10!. Display only the final value using the function "disp"

采纳的回答

Kate Heidingsfelder
kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)

更多回答(2 个)

Anusha
Anusha 2023-10-25
kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)

Anusha
Anusha 2023-10-25
kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by