Using a "while" loop to calculate a factorial

9 views (last 30 days)
Use a while loop to calculate f=10!. Display only the final value using the function "disp"
  2 Comments
James Tursa
James Tursa on 20 Feb 2021
What have you done so far? What specific problems are you having with your code?

Sign in to comment.

Accepted Answer

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

More Answers (2)

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

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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!