Using a "while" loop to calculate a factorial

16 Ansichten (letzte 30 Tage)
Kate Heidingsfelder
Kate Heidingsfelder am 20 Feb. 2021
Beantwortet: Anusha am 25 Okt. 2023
Use a while loop to calculate f=10!. Display only the final value using the function "disp"
  2 Kommentare
James Tursa
James Tursa am 20 Feb. 2021
What have you done so far? What specific problems are you having with your code?
Kate Heidingsfelder
Kate Heidingsfelder am 20 Feb. 2021
I figured it out! Thanks though!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (2)

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

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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by