필터 지우기
필터 지우기

While loop for sum

조회 수: 4 (최근 30일)
Rui Hou
Rui Hou 2021년 4월 12일
댓글: Rui Hou 2021년 4월 12일
Hi,
I need to read in an integer N from the keyboard and then use while loop to compute the value of the expression.
The expression is ((n+1)/sqrt(n)+n^3)

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 12일
n = 1;
while true
do something
n = n + 1;
if n > N; break; end
end
or
n = 0;
while true
n = n + 1;
if n > N; break; end
do something
end
or
n = 1;
while true
do something
if n >= N; break; end
n = n + 1;
end
or
n = 1;
while n <= N
do something
n = n + 1;
end
or
n = 0;
while true
if n > N; break; end
n = n + 1;
do something
end
  댓글 수: 1
Rui Hou
Rui Hou 2021년 4월 12일
That helps! Thank you!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by