Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Issues with while loop

10 visualizaciones (últimos 30 días)
Marius Reikerås
Marius Reikerås el 27 de Oct. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Im writing a code to check if my input number is bigger than sqrt 132 and is dividable by 11. Under is my code, i get errors and dont understand what im doing wrong. Thanks for any advice!
x = input(' any number ')
odd = rem(x, 2) == 0
while x > sqrt(132)
if x / 11
fprintf( 'correct/n')
else
fprintf('Try again/n')
end
end

Respuestas (1)

Cris LaPierre
Cris LaPierre el 27 de Oct. de 2020
You have no exit criteria for your while loop, which means you are creating an infinite loop.
Do you even need a while loop? It doesn't sound like there are any repeat calculations in your task. Try using an if statement instead.

La pregunta está cerrada.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by