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

更多回答(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