Using a "while" loop to calculate a factorial

Use a while loop to calculate f=10!. Display only the final value using the function "disp"

2 Comments

What have you done so far? What specific problems are you having with your code?
I figured it out! Thanks though!

Sign in to comment.

 Accepted Answer

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

More Answers (2)

kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)
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!