Using a "while" loop to calculate a factorial

18 visualizaciones (últimos 30 días)
Kate Heidingsfelder
Kate Heidingsfelder el 20 de Feb. de 2021
Respondida: Anusha el 25 de Oct. de 2023
Use a while loop to calculate f=10!. Display only the final value using the function "disp"
  2 comentarios
James Tursa
James Tursa el 20 de Feb. de 2021
What have you done so far? What specific problems are you having with your code?
Kate Heidingsfelder
Kate Heidingsfelder el 20 de Feb. de 2021
I figured it out! Thanks though!

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (2)

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

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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by