For and while loops
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Danny Maefengea
il 22 Giu 2020
Commentato: Walter Roberson
il 22 Giu 2020
Hi everyone,
How can I write a Matlab function that takes an input integer n and computes the following
n!=n×(n−1)×(n−2)⋯ ×2×1 by using:
The while loop and name it getFacWhile(n).
The for loop and name it getFacFor(n).
Risposta accettata
Ashish Azad
il 22 Giu 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 Commento
Walter Roberson
il 22 Giu 2020
We recommend against providing complete solutions to homework problems.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!