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 Commenti

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

Accedi per commentare.

 Risposta accettata

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

Più risposte (2)

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

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by