Using a "while" loop to calculate a factorial

19 vues (au cours des 30 derniers jours)
Kate Heidingsfelder
Kate Heidingsfelder le 20 Fév 2021
Réponse apportée : Anusha le 25 Oct 2023
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?
Kate Heidingsfelder
Kate Heidingsfelder le 20 Fév 2021
I figured it out! Thanks though!

Connectez-vous pour commenter.

Réponse acceptée

Kate Heidingsfelder
Kate Heidingsfelder le 20 Fév 2021
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
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
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 Help Center 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