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 commentaires

James Tursa
James Tursa le 20 Fév 2021
What have you done so far? What specific problems are you having with your code?
I figured it out! Thanks though!

Connectez-vous pour commenter.

 Réponse acceptée

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

Plus de réponses (2)

Anusha
Anusha le 25 Oct 2023

0 votes

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

0 votes

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

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by