For and while loops

2 visualizaciones (últimos 30 días)
Danny Maefengea
Danny Maefengea el 22 de Jun. de 2020
Comentada: Walter Roberson el 22 de Jun. de 2020
Hi everyone,
How can I write a Matlab function that takes an input integer n and computes the following
n!=n×(n1)×(n2)×2×1 by using:
The while loop and name it getFacWhile(n).
The for loop and name it getFacFor(n).
  1 comentario
KSSV
KSSV el 22 de Jun. de 2020
What have you tried?

Iniciar sesión para comentar.

Respuesta aceptada

Ashish Azad
Ashish Azad el 22 de Jun. de 2020
function F = getFacWhile(n)
F=1;
while n>1
F=F*n;
n=n-1;
end
end
function F = getFacWhile(n)
F=1;
for i=1:n
F=F*i;
end
end
  1 comentario
Walter Roberson
Walter Roberson el 22 de Jun. de 2020
We recommend against providing complete solutions to homework problems.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by