Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Evan Charlesworth
Evan Charlesworth le 11 Nov 2018
factor cannot be the number we are testing
  1 commentaire
Evan Charlesworth
Evan Charlesworth le 11 Nov 2018
Modifié(e) : madhan ravi le 11 Nov 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

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by