While loop for sum

4 visualizaciones (últimos 30 días)
Rui Hou
Rui Hou el 12 de Abr. de 2021
Comentada: Rui Hou el 12 de Abr. de 2021
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)

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Abr. de 2021
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 comentario
Rui Hou
Rui Hou el 12 de Abr. de 2021
That helps! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by