Using a "while" loop to calculate a factorial

조회 수: 21 (최근 30일)
Kate Heidingsfelder
Kate Heidingsfelder 2021년 2월 20일
답변: Anusha 2023년 10월 25일
Use a while loop to calculate f=10!. Display only the final value using the function "disp"
  댓글 수: 2
James Tursa
James Tursa 2021년 2월 20일
What have you done so far? What specific problems are you having with your code?
Kate Heidingsfelder
Kate Heidingsfelder 2021년 2월 20일
I figured it out! Thanks though!

댓글을 달려면 로그인하십시오.

채택된 답변

Kate Heidingsfelder
Kate Heidingsfelder 2021년 2월 20일
kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)

추가 답변 (2개)

Anusha
Anusha 2023년 10월 25일
kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)

Anusha
Anusha 2023년 10월 25일
kk = 10;
k = 1;
f = 1;
while k <= kk
f = k * f;
k = k + 1;
end
format long
disp(f)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by