Borrar filtros
Borrar filtros

How to find the largest factor of a number using while loops?

2 visualizaciones (últimos 30 días)
factor cannot be the number we are testing
  1 comentario
Evan Charlesworth
Evan Charlesworth el 11 de Nov. de 2018
Editada: madhan ravi el 11 de Nov. de 2018
I've gotten this so far, but don't know where to go from here.
largestfactor=n-1;
while largestfactor>0
if mod(n,largestfactor)==0

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 11 de Nov. de 2018
largestfactor=floor(n/2);
while largestfactor>0
if mod(n,largestfactor)==0
break
end
largestfactor = largestfactor-1;
end

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by